Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Update Stop Loss from ATM Strategy

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

    Update Stop Loss from ATM Strategy

    I have started the ATM strategy by using,
    StartAtmStrategy(atmStrategySelector.SelectedAtmSt rategy.DisplayName, entryOrder);

    However, i would like to update the Stop Loss. I have tried, startAtmStrategy.SetStopLoss("Entry", CalculationMode.Price, stopPrice, false); but it creates an additional order instead of shifting the existing one from the ATM Strategy.

    I have also tried, startAtmStrategy.AtmStrategyChangeStopTarget(0, stopPrice, "Stop" + i, atmStrategyId); where i get the Id
    atmStrategyId = startAtmStrategy.Id.ToString();
    but somehow, its not the correct Id.

    #2
    Hello twelvester,

    Thank you for your post. Are you saving the ATM Strategy ID to a variable when the strategy is created, as in the Sample ATM Strategy that comes preinstalled with NinjaTrader? If you're modifying that script, there's an example of changing the Stop Loss price in there using the saved ATM Strategy ID:

    Code:
                if (atmStrategyId.Length > 0)
                {
                    // You can change the stop price
                    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
                        AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
    
                    // Print some information about the strategy to the output window, please note you access the ATM strategy specific position object here
                    // the ATM would run self contained and would not have an impact on your NinjaScript strategy position and PnL
                    Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
                    Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
                    Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId));
                    Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
                }
    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Can I use the Indicator class instead?
      Because i have created my custom Chart Control Buttons and i use the ATM Strategy selector etc. I initially used the Strategy class, but when i load the strategy i have to select the Account. Changing the account in the Chart Trader will not affect the selected account in the strategy, which would then cos the trade to fill on the wrong account.

      Comment


        #4
        Hello twelvester,

        Thank you for your reply.

        Ah, okay, I see why you're using the AddOn methods then.

        No, you wouldn't be able to use the Strategy methods for working with ATMs in an indicator, you would need to use the add-on methods. I'd recommend checking that out here:



        Specifically you'd want to look at lines 1656 and 1462, but with the Orders[i] from lines 1887 - 1889.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Do i need to change this to an AddOn class or stick with the Indicator class

          Comment


            #6
            Hello twelvester,

            Thank you for your reply.

            AddOn code may be used within other types of scripts, so yes, you could use that in an indicator.

            Please let us know if we may be of further assistance to you.

            Comment


              #7
              I have this method added:

              private void OnPositionUpdate(object sender, PositionEventArgs e)
              {
              try
              {
              Print("OnPositionUpdate: " + e.ToString());

              Print("OnPositionUpdate: MarketPosition " + startAtmStrategy.Position.MarketPosition);
              if (startAtmStrategy.Position.MarketPosition == MarketPosition.Long ||
              startAtmStrategy.Position.MarketPosition == MarketPosition.Short)
              {

              if (e.Operation == Operation.Add)
              {
              Print("OnPositionUpdate atmStrategyId: " + atmStrategyId);
              int qty = e.Position.Quantity;
              for (int i = 1; i <= qty; i++)
              {
              Print("stop" + i + " :: " + stopLossPrice);
              startAtmStrategy.AtmStrategyChangeStopTarget(0, stopLossPrice, "Stop" + i, atmStrategyId);
              }
              }
              }
              }
              catch (Exception exception)
              {
              Print(exception.StackTrace);
              }
              }

              But i cannot seem to obtain the correct atmStrategyId as i get this Error message "'AtmStrategyChangeStopTarget' method error: ATM strategy ID '206864886' does not exist or is already in a terminated state"

              when i click my button, i set the global atmStrategyId as follow:
              startAtmStrategy = NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy(atmStrategySelector.SelectedAtmStrategy, entryOrder);
              Print(startAtmStrategy.ToString());
              atmStrategyId = startAtmStrategy.Id.ToString();

              Could you let me know what is the proper method to obtain the atmStrategyId. Thanks

              Comment


                #8
                Originally posted by NinjaTrader_Kate View Post
                Hello twelvester,

                Thank you for your reply.

                AddOn code may be used within other types of scripts, so yes, you could use that in an indicator.

                Please let us know if we may be of further assistance to you.
                Hi Kate,

                I do need some help with obtaining the atmStrategyId. Thanks.

                Comment


                  #9
                  Hello twelvester,

                  Thank you for your replies.

                  You wouldn't be able to use AtmStrategyChangeStopTarget if you're using the AddOn methods - that's a method specific to strategies and isn't available to AddOns.

                  Line 1878 in the framework example shows how to use <atmstrategy>.GetStopOrders(). Once you have used <atmStrategy>.GetStopOrders() or whatever you prefer to get the order, here is an example of how to change the price of the order:



                  Please let us know if we may be of further assistance to you.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  675 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  379 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  111 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  578 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  584 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X