Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trouble with Profit Target * ATR

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

    Trouble with Profit Target * ATR

    Hi,
    I'm trying to use the ATR in SetProfitTarget.

    My code snippet for this is:
    SetProfitTarget(Position.AvgPrice +(ATR(14)[1])*2);

    In plain language, I'm trying to set a profit target 2* the ATR above my entry price. However, in backtesting, I am getting orders executed at a price of ATR(14)[1]*2, instead of adjusted by this amount from my entry price. Any ideas on what's going wrong here?

    Thank you

    #2
    Trader5555, are you setting this in your strategy Initialize() or OnBarUpdate()?

    Comment


      #3
      I have had the same result setting this in both places. However, because the profit target should not change after the order is entered, I believe I should be setting this in Initialize().

      Comment


        #4
        Thanks for the reply, but the ATR of the bars is a dynamic value, thus you would need to set it then in OnBarUpdate(). Please set the target as your in a position as then the Position.AvgPrice would have a value.

        Comment


          #5
          A slightly different issue arises with the following code snippet set in the OnBarUpdate():

          SetStopLoss(Low[BarsSinceEntry("")]- ATR(14)[BarsSinceEntry("")]); SetProfitTarget(Position.AvgPrice +(ATR(14)[BarsSinceEntry("")])*2);

          In this case, either the Stop Loss or Profit Target are triggered immediately in backtesting. The Profit Target seems to be set at the entry price instead of at the entry price plus the ATR at the time of entry * 2.

          Comment


            #6
            You would need to take care to submit them then at the correct point in the OnBarUpdate(), BarsSinceEntry at the entry directly would not yield anything significant for your task here.

            It would be easiest if your print or visualize the stop / target levels via a drawing tool to debug the values you would get at which exact point in time as the trade progresses.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            67 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            149 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            162 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            99 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            286 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X