Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategyChangeStopTarget -- How to change Profit and Stop price

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

    AtmStrategyChangeStopTarget -- How to change Profit and Stop price

    Hello,

    I am having trouble when using AtmStrategyChangeStopTarget for changing profit target and stop loss. I am getting a log error 'Target1 is invalid.

    I am providing a sample of your SampleAtmStrategy which was edited to move Target to make this easy

    Here is the code I have added for the target


    Code:
    // You can change the stop price
    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
    AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
    AtmStrategyChangeStopTarget(0, High[0] + 3 * TickSize, "TARGET1", atmStrategyId);
    Thanks in advance,

    BeachTrader​
    Attached Files

    #2
    Hello, thanks for writing in. You need to make sure the atmStrategyID length is > 0 before calling this method to make sure the ATM is active:
    Code:
    if (atmStrategyId.Length > 0)
        AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);

    Comment


      #3
      Hi NinjaTrader_ChrisL, I should have posted more of the code. atmStrategyId.Length was checked before attempting to move the stop and target. Again this is a edit of the SampleAtmStrategy, I have just added the line to move "TARGET1" as well.

      Do I need to check the ID length before each instance of the command? ie. once for stop loss and once for target?

      Thanks for your help on this, I just cant seem to get it to work.

      Code:
      if (atmStrategyId.Length > 0)
      {
      // You can change the stop price
      if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
      AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "STOP1", atmStrategyId);
      AtmStrategyChangeStopTarget(0, High[0] + 3 * TickSize, "TARGET1", 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)) ;
      }

      Comment


        #4
        A quick clarification, The "move stop loss" is working, I am specifically having an issue with the target being moved.

        Cheers!

        Comment


          #5
          Hi, Your Target order is going to be a Limit order, not a stop order. You will need to have a value in the first parameter and leave the stop price at 0.

          Comment


            #6
            Worked like a charm!! thanks so much, I knew It was going to be something silly on my part, lol

            Cheers!

            BeachTrader

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            52 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            70 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            43 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            48 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X