calling the AverageTrueRange (ATR) value at a previous candle

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #229942 quote
    juld63
    Participant
    New

    Hi everyone,

    I am defining my stop loss as a function of the ATR and I would like this ATR to be, not the ATR value at the current candle, but the ATR value as it was at the opening of the trade.

    I thought it would be as simple as writing

    ATR=AverageTrueRange[10](close[BarIndex-TradeIndex])

    but instead it throws everything off. The backtest just accumulates massive losses on the very first trade of the period. And since the formula includes “TradeIndex”, I can’t program an indicator to see what values it produces.

    Am I missing something obvious?

     

    Thanks a lot !

     

    #229944 quote
    PeterSt
    Participant
    Master

    Hi there,

    You could start with a command

    Graph TradeIndex

    in order to see whether that remains the same throughout the open position. This is not necessarily so ! (depending on what you further do when the position is running).
    If that remains the same, then consider whether the logic is OK (I can’t tell but it looks weird ?).
    Otherwise it seems to me that you could have something like this :

    Once ATR = 0
    If OnMarket and not OnMarket[1] then   // Just opened a new position ?
      ATR=AverageTrueRange[10](close)
    endif
    
    // And from here on use the ATR variable.
    
    #229963 quote
    JS
    Participant
    Senior

    Hi,

    What is important for such calculations is that your ATR -calculation is in the “IF-Then” statement:

    If myConditions then

    Buy 1 contract at Market

    ATR=AvarageTrueRange[10](Close[BarIndex-TradeIndex])

    EndIf

    Set Stop PLoss ATR

    Set Take Profit (2*ATR)

    If your calculation is outside the “IF-Then” then the ATR values will change every time the code is recalculated … (at the Close of the Bar)

    #230297 quote
    LucasBest
    Participant
    Average
    If you define ATR as : ATR = AverageTrueRange[10](close) then, ATR value at TradeIndex is : MyStopLoss = ATR[BarIndex-TradeIndex] Anyway, the best option is to define the stop loss just after th buy instruction with “Set Stop PLoss ATR”
    #230459 quote
    juld63
    Participant
    New
    Thanks a lot everyone!
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

calling the AverageTrueRange (ATR) value at a previous candle


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
juld63 @juld63 Participant
Summary

This topic contains 4 replies,
has 4 voices, and was last updated by juld63
1 year, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/18/2024
Status: Active
Attachments: No files
Logo Logo
Loading...