//------------------------------------------------------------------------//
//PRC_Volatility Stop
//version = 0
//15.04.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//------------------------------------------------------------------------//
//-----Inputs-------------------------------------------------------------//
length=20
mult=2
src=customclose
//------------------------------------------------------------------------//
//-----ATR calculation----------------------------------------------------//
atr=averagetruerange[length](close)
//------------------------------------------------------------------------//
//-----Stop calculation--------------------------------------------------//
if barindex < length then
max1=src
min1=src
mystop=0
else
//-----Control levels
max1=max(max1[1],src)
min1=min(min1[1],src)
if trendUP then
//-----Stop in Uptrend
mystop=max(mystop,max1-atr*mult)
r=0
g=255
else
//-----Stop in DownTrend
mystop=min(mystop,min1+atr*mult)
r=255
g=0
endif
//---------------------------------------------------------------------//
//-----Trend UP definition---------------------------------------------//
trendUp=(src-mystop) >= 0
//---------------------------------------------------------------------//
//-----Signals when trend changes--------------------------------------//
if trendUP <> trendUP[1] then
max1=src
min1=src
if trendUp then
mystop=max1-atr*mult
drawpoint(barindex,mystop,3)coloured("blue",50)
drawtext("▲",barindex,mystop-0.25*tr)coloured("green")
else
mystop=min1+atr*mult
drawpoint(barindex,mystop,3)coloured("blue",50)
drawtext("▼",barindex,mystop+0.25*tr)coloured("red")
endif
endif
endif
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
return mystop as "Stop"style(line,2) coloured(r,g,0)