//06.05.2021
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
//converted from MQL5
// --- settings
//RISK=3
//SSP=9
//AtrRatio=0.375
// --- end of settings
once K = 33-RISK
once ATRPeriod=15
if barindex>max(SSP,ATRPeriod) then
//---
//trend=oldtrend
WPR = Williams[SSP](close)
ATR = AverageTrueRange[ATRPeriod](close)
if(WPR<-100+K) then
trend=-1
endif
if(WPR>-K) then
trend=1
endif
irange=AtrRatio*ATR
//---
if(trend[1]<0 and trend>0) then
BuyBuffer=low-irange
else
Buybuffer = 0 //nst
endif
if(trend[1]>0 and trend<0) then
SellBuffer=high+irange
else
SellBuffer = 0 //nst
endif
if(trend>0) then
if(BuyBuffer) then
UpBuffer1=BuyBuffer
DnBuffer1=DnBuffer1[1]
else
istop=low-irange
if(istop<UpBuffer1[1]) then
istop=UpBuffer1[1]
endif
UpBuffer1=istop
endif
endif
if(trend<0) then
if(SellBuffer) then
DnBuffer1=SellBuffer
UpBuffer1=UpBuffer1[1]
else
istop=high+irange
if(istop>DnBuffer1[1]) then
istop=DnBuffer1[1]
endif
DnBuffer1=istop
endif
endif
endif
//---
if (trend[1]>0 and trend>0) then
r=50
g=205
b=50
dn=0
up=255
elsif (trend[1]<0 and trend<0) then
r=148
g=0
b=211
dn=255
up=0
endif
if buybuffer then
drawtext("✵",barindex,upbuffer1,dialog,bold,25) coloured(50,205,50)
elsif sellbuffer then
drawtext("✵",barindex,dnbuffer1,dialog,bold,25) coloured(148,0,211)
endif
return upbuffer1 coloured(r,g,b,up) style(line,2),dnbuffer1 coloured(r,g,b,dn) style(line,2),TREND