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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            670 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
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X