ATR Tralingstop help

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #163154 quote
    tompa3
    Participant
    Senior

    Basically I came over this ATRtraling stop, I think it made by GraHal so thanks to him. I’m not so used to ATR but I think it works good though. Problem is that I can’t really understand the different parameters and what they mean. So if someone please can help me understand ill be grateful.
    What I’m wondering about:

    once tsincrements =  // set to 0 to ignore tsincrements
    once tsminatrdist =
    
    once tsatrperiod = // ts atr parameter
    once tsminstop =  // ts minimum stop distance
    
    once tssensitivity =  // [0]close;[1]high/low
    
    trailingstoplong = // ts atr distance
    trailingstopshort = // ts atr distance

    What parameters can I optimize and what should be set to standard values? What values is okey  to use to not overoptimize can I use decimals on some of these values or will it be a bit to much? Please give me some tips 🙂

    Whole ATR CODE:

    // %trailing stop function incl. cumulative positions
    
    once tsincrements =           // set to 0 to ignore tsincrements
    once tsminatrdist = 
    
    once tsatrperiod    =        // ts atr parameter
    once tsminstop      =          // ts minimum stop distance
    
    once tssensitivity        =     // [0]close;[1]high/low
    
    if barindex=tradeindex then
    trailingstoplong     =    // ts atr distance
    trailingstopshort    =    // ts atr distance
    else
    if longonmarket then
    if tsnewsl>0 then
    if trailingstoplong>tsminatrdist then
    if tsnewsl>tsnewsl[1] then
    trailingstoplong=trailingstoplong
    else
    trailingstoplong=trailingstoplong-tsincrements
    endif
    else
    trailingstoplong=tsminatrdist
    endif
    endif
    endif
    if shortonmarket then
    if tsnewsl>0 then
    if trailingstopshort>tsminatrdist then
    if tsnewsl<tsnewsl[1] then
    trailingstopshort=trailingstopshort
    else
    trailingstopshort=trailingstopshort-tsincrements
    endif
    else
    trailingstopshort=tsminatrdist
    endif
    endif
    endif
    endif
    tsatr=averagetruerange[tsatrperiod]((close/10)*pipsize)/1000
    //tsatr=averagetruerange[tsatrperiod]((close/1)*pipsize) // (forex)
    tgl=round(tsatr*trailingstoplong)
    tgs=round(tsatr*trailingstopshort)
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    tsmaxprice=0
    tsminprice=close
    tsnewsl=0
    endif
    if tssensitivity then
    tssensitivitylong=high
    tssensitivityshort=low
    else
    tssensitivitylong=close
    tssensitivityshort=close
    endif
    if longonmarket then
    tsmaxprice=max(tsmaxprice,tssensitivitylong)
    if tsmaxprice-tradeprice(1)>=tgl*pointsize then
    if tsmaxprice-tradeprice(1)>=tsminstop then
    tsnewsl=tsmaxprice-tgl*pointsize
    else
    tsnewsl=tsmaxprice-tsminstop*pointsize
    endif
    endif
    endif
    if shortonmarket then
    tsminprice=min(tsminprice,tssensitivityshort)
    if tradeprice(1)-tsminprice>=tgs*pointsize then
    if tradeprice(1)-tsminprice>=tsminstop then
    tsnewsl=tsminprice+tgs*pointsize
    else
    tsnewsl=tsminprice+tsminstop*pointsize
    endif
    endif
    endif
    if longonmarket then
    if tsnewsl>0 then
    sell at tsnewsl stop
    endif
    if tsnewsl>0 then
    if low crosses under tsnewsl then
    sell at market // when stop is rejected
    endif
    endif
    endif
    if shortonmarket then
    if tsnewsl>0 then
    exitshort at tsnewsl stop
    endif
    if tsnewsl>0 then
    if high crosses over tsnewsl then
    exitshort at market // when stop is rejected
    endif
    endif
    endif

    / tompa3

    #163177 quote
    GraHal
    Participant
    Master

    Above is not one of mine so I can’t help, sorry.

    If you post the link to where you found the TS then it may help folks understand the code and variable parameters etc.

    #163189 quote
    nonetheless
    Participant
    Master

    once tsincrements = // usually 0 – 0.2, effects how quickly the stop will trail
    once tsminatrdist = // 0 – 3, but this setting often has no effect at all

    once tsatrperiod = // typically 14, how many periods it looks back – not worth optimizing
    once tsminstop = // enter the minimum stop distance as set by IG, DJ = 12, NAS = 4, DAX = 5 etc

    once tssensitivity = // [0]close;[1]high/low //this chooses how the stop is triggered: 0 = when price closes above/below the trigger level, 1 = previous candle high above trigger or low if short

    trailingstoplong = // ts atr distance  // typically 3-10, this is the most important setting
    trailingstopshort = // ts atr distance // as above but usually worth optimizing separately

    Take note of line 43 if you’re trading Forex (ie use 43 and // line 42)

    I think Paul gets the credit for this TS, this is his revised version which will also work with cumulative orders. Note that he advises NOT to use ONCE with tssensitivity

    // trailing atr stop incl. cumulative positions
    once trailingstoptype2     = 1
    if trailingstoptype2 = 1 then
    //====================
    once tsincrements = tsi // set to 0 to ignore tsincrements
    once tsminatrdist = tsm
    
    once tsatrperiod    = 14 // ts atr parameter
    once tsminstop      = IG // ts minimum stop distance
    
    tssensitivity = 2 // [1] default [2] high/low [3] low/high [4] typicalprice (not use once)
    //====================
    if barindex=tradeindex then
    trailingstoplong     = tsl // ts atr distance
    trailingstopshort    = tss // ts atr distance
    else
    if longonmarket then
    if tsnewsl>0 then
    if trailingstoplong>tsminatrdist then
    if tsnewsl>tsnewsl[1] then
    trailingstoplong=trailingstoplong
    else
    trailingstoplong=trailingstoplong-tsincrements
    endif
    else
    trailingstoplong=tsminatrdist
    endif
    endif
    endif
    if shortonmarket then
    if tsnewsl>0 then
    if trailingstopshort>tsminatrdist then
    if tsnewsl<tsnewsl[1] then
    trailingstopshort=trailingstopshort
    else
    trailingstopshort=trailingstopshort-tsincrements
    endif
    else
    trailingstopshort=tsminatrdist
    endif
    endif
    endif
    endif
    tsatr=averagetruerange[tsatrperiod]((close/10))/1000
    //tsatr=averagetruerange[tsatrperiod]((close/1)) // (forex)
    tgl=round(tsatr*trailingstoplong)
    tgs=round(tsatr*trailingstopshort)
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    tsmaxprice=0
    tsminprice=close
    tsnewsl=0
    mypositionpriceatr = 0
    endif
    positioncountatr = abs(countofposition)
    if tsnewsl > 0 then
    if positioncountatr > positioncountatr[1] then
    if longonmarket then
    tsnewsl = max(tsnewsl,positionprice * tsnewsl / mypositionpriceatr)
    else
    tsnewsl = min(tsnewsl,positionprice * tsnewsl / mypositionpriceatr)
    endif
    endif
    endif
    if tssensitivity=1 then
    tssensitivitylong=close
    tssensitivityshort=close
    elsif tssensitivity=2 then
    tssensitivitylong=high
    tssensitivityshort=low
    elsif tssensitivity=3 then
    tssensitivitylong=low
    tssensitivityshort=high
    elsif tssensitivity=4 then
    tssensitivitylong=typicalprice
    tssensitivityshort=typicalprice
    endif
    if longonmarket then
    tsmaxprice=max(tsmaxprice,tssensitivitylong)
    if tsmaxprice-positionprice>=tgl*pointsize then
    if tsmaxprice-positionprice>=tsminstop then
    tsnewsl=tsmaxprice-tgl*pointsize
    else
    tsnewsl=tsmaxprice-tsminstop*pointsize
    endif
    endif
    endif
    if shortonmarket then
    tsminprice=min(tsminprice,tssensitivityshort)
    if positionprice-tsminprice>=tgs*pointsize then
    if positionprice-tsminprice>=tsminstop then
    tsnewsl=tsminprice+tgs*pointsize
    else
    tsnewsl=tsminprice+tsminstop*pointsize
    endif
    endif
    endif
    if longonmarket then
    if tsnewsl>0 then
    sell at tsnewsl stop
    endif
    if tsnewsl>0 then
    if low crosses under tsnewsl then
    sell at market // when stop is rejected
    endif
    endif
    endif
    if shortonmarket then
    if tsnewsl>0 then
    exitshort at tsnewsl stop
    endif
    if tsnewsl>0 then
    if high crosses over tsnewsl then
    exitshort at market // when stop is rejected
    endif
    endif
    endif
    mypositionpriceatr = positionprice
    endif
    GraHal, tompa3 and Midlanddave thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

ATR Tralingstop help


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
tompa3 @tompa3 Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by nonetheless
4 years, 11 months ago.

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