Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving Stop to Low of the day

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

    Moving Stop to Low of the day

    Strategy: Move all active SL stops to low of the day after taking the position.

    Should this code, as part of the indicator, move stop to low of the day?
    When trigger this code, I see the visually my gets moved, however my actual order on my exchange doesn't reflect the change, why is that?

    Code:
            private void MoveStopsToLowOfTheDay(NinjaTrader.Gui.Tools.AccountSelector chartTraderAccountSelector )
            {
                var selectedAccount = chartTraderAccountSelector.SelectedAccount;
    
                // if not correct low of the day
                if (lowOfTheDay == 0.0) { //CurrentOHL().CurrentLow[0]
                    return;
                }
                lock (selectedAccount.Orders) {
    
                 foreach (Order order in selectedAccount.Orders)
                {
                    if (order.OrderAction == OrderAction.Sell
                        && order.OrderType == OrderType.StopMarket
                        && order.OrderState == OrderState.Accepted
                        && order.Instrument.FullName == Instrument.FullName)
                    {
                        order.StopPrice = lowOfTheDay;
                        selectedAccount.Submit(new []{
                            order});
                    }
                }
                }
    
    
            }​

    #2
    Hello gbajaj,

    Thanks for your post.

    If you are wanting to change the order then you would need to use the <Account>.Change() method, not the <Account>.Submit() method. Also, you would need to use StopPriceChanged to make a new price for the stop order, not StopPrice.

    For example:

    Order stopOrder;
    stopOrder.StopPriceChanged = stopOrder.StopPrice - 4 * stopOrder.Instrument.MasterInstrument.TickSize;


    if (condition)
    {
    myAccount.Change(new[] { stopOrder });
    }


    See this help guide page for more information and sample code: https://ninjatrader.com/support/help...nt8/change.htm
    Last edited by NinjaTrader_BrandonH; 05-24-2023, 10:27 AM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you, I will test that let you know if there is a problem.
      Last edited by gbajaj; 05-24-2023, 11:31 PM.

      Comment


        #4
        Thanks it fixes the issue.
        Another question related to above code. I see this dialog "Sop price can't be moved above market." when I move the stop using above api however market price is already below the requestd change order's price.

        Is it still possible to still execute the order?

        Comment


          #5
          Hello gbajaj,

          Thanks for your notes.

          "Stop price can't be moved above market."

          This error message means that the strategy attempted to change an order to the wrong side of the market. Buy-stop orders must be placed above the current ask price. Sell-stop orders must be placed below the current bid price.

          If this is due to market volatility then there isn't really a way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this would occur.

          Something you could consider is using GetCurrentBid() and GetCurrentAsk() to offset orders so that they are more likely to land on the correct side of the market.

          See these help guide pages for more information.
          GetCurrentBid(): https://ninjatrader.com/support/help...currentbid.htm
          GetCurrentAsk(): https://ninjatrader.com/support/help...currentask.htm

          Add prints to the strategy to determine why the stop order how the stop order is being submitted compared to the market price. One line above where the stop order is placed, print the GetCurrentAsk()/GetCurrentBid() and print the price being submitted to the order method to compare.

          You could also consider using RealtimeErrorHandling.IgnoreAllErrors to trap order errors in OnOrderUpdate().

          Please note that setting this property value to IgnoreAllErrors can have serious adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method. To do this you could trap the rejected order by checking if the OrderState is Rejected within OnOrderUpdate() if this is a rejected order followed by defining your own order rejection handling behavior for the rejected order.

          Please see the example in the help guide link below that demonstrates using RealtimeErrorHandling and trapping a rejected order in OnOrderUpdate().

          RealtimeErrorHandling — https://ninjatrader.com/es/support/h...orhandling.htm
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          656 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X