Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on implementing ATR Trailing Stop

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

    Error on implementing ATR Trailing Stop

    Here is the code (attached). Where did I make mistake ... argggh .... and I am new to this ..... help please

    Basically, I want ATR Trailing stop with size of 2 times ATR
    Attached Files

    #2
    cowcool, please try moving your Math.Ceiling calculations to the OnBarUpdate() section.

    Comment


      #3
      Thx but the problem is if it is moved to onBarUpdate, the ATR value is constantly changing. I want it to be static , i.e. the ATR value just before a trade is entered.

      Originally posted by NinjaTrader_Bertrand View Post
      cowcool, please try moving your Math.Ceiling calculations to the OnBarUpdate() section.

      Comment


        #4
        Well, then set this variable with the ATR value at the point your trade entry triggers, then it's using this value forward as stop amount.

        Comment


          #5
          Tried to move all the variables to onbarupdate but got error (please see the attached image ) thx


          Originally posted by NinjaTrader_Bertrand View Post
          Well, then set this variable with the ATR value at the point your trade entry triggers, then it's using this value forward as stop amount.
          Attached Files

          Comment


            #6
            This is most likely because you miss the matching curly bracket to end the OnBarUpdate(). However, you can leave the Variables declaration where you had them previously. Then just set the value for your stop amount when your trade triggers -

            Code:
             
            if (Close[0] > Close[5])
            {
            EnterLong(1, "");
            myStopValue = Close[0] - 2 * ATR(10)[0];
            }
            
            if (Position.MarketPosition == MarketPosition.Long)
            SetStopLoss(CalculationMode.Price, myStopValue);
            You can also check into this reference sample -

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            649 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
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X