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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            67 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            36 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            60 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            62 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            53 views
            0 likes
            Last Post CarlTrading  
            Working...
            X