• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using SetTrailStop and SetProfitTarget

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Using SetTrailStop and SetProfitTarget

    I have a strategy that uses SetTrailStop and SetProfitTrarget. I am encountering a problem where sometimes (only sometimes) when I have a trade that hits the profit target, I get an error which appears to causes NT to flatten the position and cancel any open orders but apparently without cancelling the profit target which causes an entry in the opposite direction. The error I am getting is that NT is trying to update my trailing stop price to the same value it is already set at. In my code, I only call the SetTrailStop once, OnBarUpdate, at the time I submit the original order. I also call the SetProfitTarget at that same time. See code sample below.

    if (entrycriteriamet)
    {
    if (otherentrycriteriamet)
    {
    EnterLong(Convert.ToInt32(NumberOfContracts), @"T1_LONG");
    sv_profittarget = sv_s1_high+(TickSize*2);
    SetProfitTarget(@"T1_LONG", CalculationMode.Price, sv_profittarget, true);
    SetTrailStop(@"T1_LONG", CalculationMode.Ticks, 8, false);
    }
    }

    Here is some of my log showing the error.

    Order='1930029853/W0628' Name='Trail stop' New state='Accepted' Instrument='ES 09-19' Action='Sell' Limit price=0 Stop price=2987.5 Quantity=1 Type='Stop Market' Time in force=GTC Oco='253205498112' Filled=0 Fill price=0 Error='Unable to change order' Native error='Cannot change order '1930029853' because current order values already match.'

    Strategy 'STRATEGY1/170820685' submitted an order that generated the following error 'Unable to change order'. Strategy has sent cancel requests, attempted to close the position and terminated itself.

    I'd love some feedback on if this is a know issue or if there is some way I can change the code to prevent this issue. I have the entire log showing the original entry and all the log entries that occurred the entire trade, if needed.

    #2
    Hello pparmley,

    Thanks for your first post!

    The Set methods (SetProfitTarget, SetStopLoss, and SetTrailStop) will all retain their last used value. It is critical, especially when using the CalculationMode.Price that you set the price value before you place the entry order. I suspect that as you are placing the entry order and then calculating the profit target that the previous value of profit target is employed before you can set it to the newest value. A simple solution here may be to move the entry order code to the bottom of that code block so that you are first calculating the profit target, then setting the profit target, then setting the trail stop and then finally placing the entry order.

    For reference, in each of the Set methods help guide section you will find this (or similar) statement: "Should you call this method to dynamically change the target price in the strategy OnBarUpdate() method, you should always reset the target price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your profit target order on your next open position" Reference: https://ninjatrader.com/support/help...ofittarget.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul H., I appreciate your reply. I will definitely move my entry after I set the profit target and trailing stop, as this is the NT recommended method. However, I am not confident this will resolve my issue. My issue was not that the profit target or trailing stop was the wrong price. The profit target and trailing appear correct for the entire trade. My issue was that when I hit my profit target, according to the log, the trailing stop seems to try and update again (because the price moved up, of course) but for some reason tries to set the trailing stop to the same price it already was, which throws an error causing the strategy to exit and disable. Again, I will make this change to the code and see if it has any impact on the strategy, but if you have any other suggestions, I would appreciate it.

      Comment


        #4
        Hello pparmley,

        Thanks for your reply.

        If you continue to see the same, please write into PlatformSupport[at]NinjaTrader[dot]Com and provide your log and trace files along with your strategy for review (or a small version of your strategy that demonstrates the issue). Mark the e-mail Atten:Paul and please include a link to this thread.

        Here are the steps to add your log/trace files to your e-mail:
        • Open your NinjaTrader folder under, "Documents" (sometimes called, "My Documents")
        • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
        • Send the 2 compressed folders as attachments to the email.
        • Once complete, you can delete these compressed folders.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sidviciousX, Today, 06:47 AM
        0 responses
        2 views
        0 likes
        Last Post sidviciousX  
        Started by samir, 04-17-2019, 01:20 PM
        4 responses
        30 views
        0 likes
        Last Post gviand
        by gviand
         
        Started by Debayan Sen, Today, 01:50 AM
        0 responses
        7 views
        0 likes
        Last Post Debayan Sen  
        Started by eleven, Yesterday, 10:03 PM
        1 response
        11 views
        0 likes
        Last Post eleven
        by eleven
         
        Started by tvbecv, Yesterday, 09:23 PM
        0 responses
        8 views
        0 likes
        Last Post tvbecv
        by tvbecv
         
        Working...
        X