Skip to main content

Average True Range Trailing Stops for Metastock

matz over 15 years ago Metastock

  • Rating:
    0 / 5 (Votes 0)
  • Tags:
    metastock, stop loss, atr

The formula to implement the average true range (ATR) trailing stop loss method for MetaStock, as described by author Sylvain Vervoort In “Average True Range Trailing Stops” article, is provided below.

Signals are used for exits:

  • If in a long position exit (sell) when price crosses below the ATR trailing stop line.
  • If in a short position exit (buy) when price crosses above the ATR trailing stop line.

Screenshots

Files

Indicator / Formula

Copy & Paste Friendly
{SVE_Stop_Trail_ATR_Mod}

period:=Input("ATR period :",1,100,5);
atrfact:=Input("ATR multiplication :",1,10,3.5);
HiLo:=If(H-L<1.5*Mov(H-L,period,S),H-L, 1.5*Mov(H-L,period,S));
Href:=If(L<=Ref(H,-1),H-Ref(C,-1),(H-Ref(C,-1))-(L-Ref(H,-1))/2);
Lref:=If(H>=Ref(L,-1),Ref(C,-1)-L,(Ref(C,-1)-L)-(Ref(L,-1)-H)/2);
diff1:=Max(HiLo,Href);
diff2:=Max(diff1,Lref);
atrmod:=Wilders(diff2,period);
loss:=atrfact*atrmod;

trail:=
If(C>PREV AND Ref(C,-1)>PREV,
Max(PREV,C-loss),
If(C<PREV AND Ref(C,-1)<PREV,
Min(PREV,C+loss),
If(C>PREV,C-loss,C+loss)));

Trail

0 comments

Leave Comment

Please login here to leave a comment.