Escaping of Rate from Avarage By Mustafa OZVER Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mustafaozver

//@version=4
strategy("Escaping of Rate from Avarage By Mustafa OZVER", "EoRfA", overlay=false)
//strategy("Escaping of Rate from Avarage By Mustafa OZVER", "EoRfA", overlay=false)

src = input(ohlc4,"Source")
FPrice = wma(src,3)
len = input(17,"Length")

stdev = stdev(FPrice,len)
ema2 = ema(FPrice,len)

Rate1 = (FPrice - ema2) / stdev
//bgcolor(color=((stdev/ema)>0.0015)?color.green:#00000000,transp=80)

colorG = color.lime
colorR = color.red

hline(0,linestyle=hline.style_solid,editable=false)
hline1=hline(1,linestyle=hline.style_dotted,editable=false)
hlinen1=hline(-1,linestyle=hline.style_dotted,editable=false)
fill(hline1,hlinen1,color=color.silver,transp=85,editable=true)

//plot(Rate,color=(Rate>0?colorG:colorR),transp=75,style=plot.style_area,editable=false)

plot(Rate1,title="ESC1",color=(Rate1>0?colorG:colorR),style=plot.style_line,linewidth=1,editable=true)

BUYSIGNAL = Rate1 < -1 and change(Rate1) > 0
SELLSIGNAL = Rate1 > 1 and change(Rate1) < 0

if (BUYSIGNAL)
    strategy.order("LONG1",true)
    //strategy.close("SHORT1")

if (SELLSIGNAL)
   // strategy.order("SHORT1",false)
    strategy.close("LONG1")