Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing the ATM stop through an indicator.

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

    Changing the ATM stop through an indicator.

    I'm trying to control my ATM stop through an indicator. I want the stop to trail the low of the prior bar.
    This is how I had it in my strategies:
    Code:
    AtmStrategyChangeStopTarget(0, Low[1], "Stop1", "ATM 1");
    How would this translate for an indicator?
    Thank you.

    #2
    Hello KINGKODA,

    For an indicator you would need to get the order from the Account.Orders collection and the call Account.Change() with the new price.



    The examples may give you some ideas.
    https://ninjatraderecosystem.com/use...egyidentifier/
    ProfitChaseStopTrailIndicatorExample - https://forum.ninjatrader.com/forum/...269#post802269
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you so much. This is what I have been able to extract from the links but it doesn't seem to be working.
      I've tried OnPositionUpdate and OnExecutionUpdate.

      Code:
      private void OnPositionUpdate(object sender, PositionEventArgs e)
      {
           if (e.MarketPosition == MarketPosition.Long)
           {
                limitOrder.StopPriceChanged = limitOrder.AverageFillPrice - 20*limitOrder.Instrument.MasterInstrument.TickSize;
                myAccount.Change(new[] {limitOrder});
           }
      }​
      My order executes as follows:
      Code:
      if (priceClicked > Close[0])
      {      limitOrder = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.StopLimit, OrderEntry.Manual, TimeInForce.Day, quantity, priceClicked, priceClicked, "", "Entry", DateTime.MaxValue, null);
        ​
             NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy("ATM 1", limitOrder);
       }
      else if (priceClicked < Close[0])
      {      limitOrder = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.Limit, OrderEntry.Manual, TimeInForce.Day, quantity, priceClicked, 0, "", "Entry", DateTime.MaxValue, null);
      ​
           NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy("ATM 1", limitOrder);
       }
      
      myAccount.Submit(new[] { limitOrder});​

      How can I change the stop price of the ATM that's working on my limitOrder?

      Thank you again.
      Last edited by KINGKODA; 08-31-2023, 12:41 PM.

      Comment


        #4
        Hello KINGKODA,

        The price would be changed with the Account.Change() method.
        This is demonstrated on lines 130 to 158 of the ProfitChaseStopTrailIndicatorExample within OnBarUpdate().

        In the code you have posted you are using limitOrder as the entry order.
        Then you are attempting to change the entry order after the position changes to long. If the entry order has filled, the order can no longer be changed.

        To change the stop price of the stop loss from the atm, you will need to find the order from the Account.Orders collection as the Account.OrderUpdate event runs.

        This is demonstrated on lines 289 to 293 and 187 to 214 in the AtmStrategyIdentifier.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you so much for that explanation. I better understand the order lifecycle and was able to create the collection of orders as shown in the AtmStrategyIdentifier.

          In the ProfitChaseStopTrailIndicatorExample, the target and stop are manually submitted and do not belong to an active ATM strategy. To update target price it checks for the status of the profittarget order through OrderState:
          Code:
          if (ChaseProfitTarget && profitTargetOrder != null &&
          (profitTargetOrder.OrderState == OrderState.Accepted || profitTargetOrder.OrderState == OrderState.Working) &&
          Close[0] < currentPtPrice - ProfitTargetDistance * TickSize)
          {
               currentPtPrice                        = Close[0] + ProfitTargetDistance * TickSize;
               profitTargetOrder.LimitPriceChanged = currentPtPrice;
               changeOrdersArray.Add(profitTargetOrder);
          
               if (PrintDetails)
                    Print(string.Format("{0} | OOU | chasing target, currentPtPrice: {1}", Time[0], currentPtPrice));
          }​
          How would this translate to getting the atm target from the list I created? Because from my understanding, my limitOrder is only the Limit Order that gets placed for entry. Once it is filled, the ATM Strategy ProfitTarget and StopLoss are two different orders that cannot be manipulated by checking the OrderState of limitOrder. If this is true, then how can I access the stop order that I have saved in the atmDictionary?

          My goal is to manipulate the stop but the example gives the target getting manipulated so I wouldn't mind having both in this indicator but in regards to the ATM orders and not manually placed orders.
          Last edited by KINGKODA; 08-31-2023, 10:36 PM.

          Comment


            #6
            Hello KINGKODA,

            "my limitOrder is only the Limit Order that gets placed for entry. "

            That would be the entry order.

            "Once it is filled, the ATM Strategy ProfitTarget and StopLoss are two different orders that cannot be manipulated by checking the OrderState of limitOrder. "

            You wouldn't be checking the state of the entry order. The profit target and stop loss orders will be found through the Account.Orders collection (or Account.OrderUpdate event) and then assigned to a variable. Then the stop or target order would be submitted to Account.Change() with a new price to change the price of the exit. The entry wouldn't be changed, but the exit orders would be changed.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            637 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            571 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X