This Stop and Reverse indicator (SAR) has been created by Welles Wilder. You can find many versions and variations of it (also the more famous 3 bar stop used by Larry Williams is based on this indicator) but this is the original coding of it.
I backtested this code and it also provide some SMALL but consistent income (unlike for example the 3 bar stop).
Rules are simple: when the price is above the SAR you remain long, when crosses below you close your long position (and you can short if you want).
Blue skies!!
//period=7
//coeff=3
mioATR=AverageTrueRange[period](close)
arc=coeff*mioATR[1]
once ref=open
if barindex=8 then
if close>=close[1] then
ref=close
mioSAR=close-arc
elsif close<close[1] then
ref=close
mioSAR=close+arc
endif
inv=barindex[1]
endif
if barindex>8 then
if close crosses under mioSAR then
mioSAR=close+arc
inv=barindex
endif
if close crosses over mioSAR then
mioSAR=close-arc
inv=barindex
endif
if close>=mioSAR and (barindex-inv)>0 then
ref=highest[barindex-inv](close[1])
mioSAR=ref-arc
endif
if close<mioSAR and (barindex-inv)>0 then
ref=lowest[barindex-inv](close[1])
mioSAR=ref+arc
endif
endif
if close>mioSAR then
red=210
blu=0
else
red=0
blu=250
endif
return mioSAR coloured (red,0,blu) as "Wilder's ARC stop"