MACD_STO-SAMI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sami1i


//@version=4
study("MACD_STO-SAMI",overlay=true)

//المدخلات 
/////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
MACD = input(false, title="-<><><><><><><><[MACD]><><><><><><><>-")

[m,s,h] = macd(close, 12, 26,9)                                                                   
 
fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
src = input(title="Source", defval=close)
signal_length = input(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])
sma_signal = input(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])

STO = input(false, title="-<><><><><><><><[STO]><><><><><><><>-")
periodK = input(8, title="%K Length", minval=1)
smoothK = input(5, title="%K Smoothing", minval=1)
periodD = input(5, title="%D Smoothing", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

SMA = input(false, title="-<><><><><><><><[SMA]><><><><><><><>-")
len = input(50, minval=1, title="Length")
src1 = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
out = sma(src1, len)
plot(out, color=color.yellow, title="MA", offset=offset)
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////




highlew = input(false, title="-<><><><><><><><[HH HL LL LH]><><><><><><><>-")

lb = input(defval = 10, title="Left Bars")
rb = input(defval = 10, title="Right Bars")

mb = lb + rb + 1



// الاختصارات


S1=(m>0 and(crossover(m,s)))
S2=(m>0 and(crossunder(m,s)))
S3=(crossover(m,s))
S4=(crossunder(m,s))


A1=(m<0 and k>80 and close < out)
A2=(m>0 and k<20 and close > out)

A3=(m>0 and k<=60 and k>=45)
A4=(m<0 and k<=60 and k>=45) 

A5=(m>0 and k<d and k<=60 and k>=45)
A6=(m<0 and k>d and k<=60 and k>=45)
A7=(m>0 and k<d and k<=65 and k>=60)
A8=(m<0 and k>d and k<=45 and k>=40)






// الاشارات 


barcolor(color=(S1)?color.green:na)
barcolor(color=(S2)?color.yellow:na)
barcolor(color=(S3)?color.blue:na)
barcolor(color=(S4)?color.red:na )

plotshape( A5 ,title="m>0 and k<d and k<=60 and k>=45", location=location.belowbar, style=shape.triangleup, size=size.tiny, color=#26f70c, transp=0)
plotshape( A6 ,title="m<0 and k>d and k<=60 and k>=45", location=location.abovebar, style=shape.triangledown, size=size.tiny, color=#fa051b, transp=0)
plotshape( A7 ,title="m>0 and k<d and k<=65 and k>=60", location=location.belowbar, style=shape.labelup, size=size.tiny, color=#00a207, transp=0)
plotshape( A8 ,title="m<0 and k>d and k<=45 and k>=40", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=#ee0971, transp=0)

bgcolor(A1?color.red:na,title="Sell",transp=0)
bgcolor(A2?color.green:na,title="Buy",transp=0)


plotshape(iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na), style =shape.labeldown, text="pH",textcolor=color.white, transp=50, location = location.abovebar, color = color.red, size = size.tiny, offset = -lb)
plotshape(iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na), style =shape.labelup,  text="pL", textcolor=color.white, transp=50,location = location.belowbar, color = color.lime, size = size.tiny, offset = -lb)


// التنبية 

alertcondition(A1,title= "Sell",message="Sell")
alertcondition(A2,title="Buy",message="Buy")

