Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

SetStopLoss Does Not Update the StopLoss

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

    SetStopLoss Does Not Update the StopLoss

    Refer to this thread for history: http://ninjatrader.com/support/forum...d.php?p=498393

    Summary: I enter a trade and call SetStopLoss. I later call SetStopLoss again with a different price. The second and any subsequent calls do not change the Stop Loss. No errors reported. It's as if it is simply ignored. Why? And how to fix, please.

    Thanks.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #2
    Hello jeronymite,

    Thank you for the post.

    Without knowing what logic in total is being used it would be difficult to provide an accurate answer. If subsequent calls are being ignored, this could be if the conditions you have created are not allowing for that to occur.

    We have an example that demonstrates updating a stops price at the following link, you could try the example and compare it to your logic to see what may be occurring as well: http://ninjatrader.com/support/forum...ead.php?t=3222

    I could still really only recommend what I have already said in the linked post. You would need to debug the script to find the cause. This could include creating a small sample of the logic being used to find the why it is not working correctly. If you do create a small sample that shows this concept not working, please feel free to post that and we could look at that specific example in more detail.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, Jesse.

      I use the following form of invocation of SetStopLoss for every invocation, including the initial one:
      Code:
      SetStopLoss(EntrySignal,CalculationMode.Price,price,false)
      So, it is specific to an individual trade each time. Other than that, the logic is simple: enter the position, update the Stop Loss price every so often. I print the inputs every time I invoke the method and they agree entirely with what is expected.

      What things could possibly cause it to be simply ignored without any error or warning?

      Thanks.
      Multi-Dimensional Managed Trading
      jeronymite
      NinjaTrader Ecosystem Vendor - Mizpah Software

      Comment


        #4
        Further information

        It appears that the SetStopLoss method is being actioned after all. However, it seems the action is delayed until either OnBarUpdate is called or the data series period expires. This is despite CalculateOnBarClose being false. It is also despite the SetStopLoss method not using simulation.

        I have created an interactive interface whereby I can submit and manage trades in real time, outside of the context of OnBarUpdate (I use a separate 1 second timer as a regular heartbeat to initiate actions). I use underlying 1 minute data series to access market data.

        If I submit an Enter order at any time, it is actioned immediately, as are any Stop Loss or Profit Target orders submitted at the same time as the entry.

        However, if I subsequently submit a revised Stop Loss order, Trace Orders shows that a SetStopTarget() method is invoked immediately ("Entered internal SetStopTarget() method"), but is not actioned to submit a real order to the market (Amended stop order) until the conditions stated above. Based on that behaviour and the 1 minute data series I have, it could be up to 1 minute before the requested change is actually executed in the market.

        How can I force these real time order requests to be actioned in the market immediately?

        Since I have multi-instrument (28) data series, it is not practical (or necessary) for me to use faster refresh data series, so that would be a major performance hit if required. There must be another way?

        Thanks.
        Multi-Dimensional Managed Trading
        jeronymite
        NinjaTrader Ecosystem Vendor - Mizpah Software

        Comment


          #5
          Hello,

          Thank you for the reply.

          Out of context, I couldn't really say what may be happening. It sounds like you have a nonstandard setup using a timer so I really couldn't comment on what may be happening there. Are you able to extract just this logic into a sample and test it separately? That would really be all I could suggest as the sample I had provided seems to work as expected while using CalculateOnBarClose = true or false.

          You could also modify the previous sample to use only real-time and test a specific concept like the following:

          Code:
          protected override void Initialize()
          {
          	SetStopLoss(CalculationMode.Ticks, 10);
                  CalculateOnBarClose = false;
          }
          
          protected override void OnBarUpdate()
          {
          	if(Historical)return;
          	if (Position.MarketPosition == MarketPosition.Flat)
          	{
          		SetStopLoss(CalculationMode.Ticks, 10);
          		EnterLong();
          	}
          	
          	else if (Position.MarketPosition == MarketPosition.Long)
          	{
          			SetStopLoss(CalculationMode.Price, Close[0] - 10*TickSize);
          	}		
          }
          This would just demonstrate changing a price from OnBarUpdate in Realtime only, this would allow you to use another chart with ChartTrader enabled to view the order changes.

          Additionally, have you tried using TraceOrders to see if you are hitting a managed order handling rule at the time the order is updated?

          Please let me know if I may be of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thanks again, Jesse.

            As mentioned previously, I determined the situation using TraceOrders. I didn't mention it, but I also used ChartTrader to verify the changes as they happened.

            I also produced a significant trace of the output from TraceOrders interlaced with other diagnostic output that I will send to you for your analysis. Trace and log files also included. Please let me know your further advice once you have had a chance to review that data.

            Thanks!
            Multi-Dimensional Managed Trading
            jeronymite
            NinjaTrader Ecosystem Vendor - Mizpah Software

            Comment


              #7
              Originally posted by jeronymite View Post
              Thanks again, Jesse.

              As mentioned previously, I determined the situation using TraceOrders. I didn't mention it, but I also used ChartTrader to verify the changes as they happened.

              I also produced a significant trace of the output from TraceOrders interlaced with other diagnostic output that I will send to you for your analysis. Trace and log files also included. Please let me know your further advice once you have had a chance to review that data.

              Thanks!
              I am seeing a similar behavior. Have you been able to figure this out?

              Comment


                #8
                Hello chaitunt,

                Thank you for your reply.

                This is a pretty old thread and I wasn't able to locate what the resolution was in this particular case. However, the first thing I would recommend for you would be to turn on the Order Trace function:

                Strategy Builder > Default Properties > More Properties > Trace Orders, or:

                if (State == State.SetDefaults)
                {
                TraceOrders = true;
                }

                Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

                Here is a link to our help guide that goes into more detail on tracing orders:



                Trace orders alone may not give you the full picture of whether or not a trade should have been entered on a given bar, so adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful.

                This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.



                If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess what is different between the two.

                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  Happens to me when paper trading with a broker in real time, was someone able to find a quick fix?
                  I was thinking about interacting with the orders directly and update the stop loss
                  after entering with EnterShortStopMarket etc.. but it seems like a lot of work..

                  Comment


                    #10
                    Hello arbel03,

                    Thank you for your reply.

                    How are you modifying your stop loss? Also, which broker are you using? TD Ameritrade, for example, does not allow you to modify a stop loss or profit target - Once an OCO pair is submitted, it must be cancelled and replaced and TD Ameritrade will not allow modifying the orders. Set method orders cannot be canceled with CancelOrder(). Exit methods will not use OCO and can work around this limitation.

                    That being said, here's an example from our help guide on modifying stop and target orders for connections that allow these modifications:



                    Thanks in advance; I look forward to assisting you further.
                    Kate W.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Kaledus, Today, 01:29 PM
                    5 responses
                    12 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Waxavi, Today, 02:00 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by alifarahani, Today, 09:40 AM
                    5 responses
                    23 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by gentlebenthebear, Today, 01:30 AM
                    3 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by PhillT, Today, 02:16 PM
                    2 responses
                    7 views
                    0 likes
                    Last Post PhillT
                    by PhillT
                     
                    Working...
                    X