PAC new
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/


//@version=5
indicator("Sma Script",overlay=true)

len_sma=input.int(4,title ="Sma Len",group="Sma Set")
scr_smah=input.source(high,title ="Sma High",group="Sma Set")
scr_smal=input.source(low,title ="Sma Low",group="Sma Set")

//sma condition

sma_h=ta.sma(scr_smah,len_sma)
sma_l=ta.sma(scr_smal,len_sma)

plot(sma_h ,title="Sma High",color=color.yellow)
plot(sma_l ,title="Sma Plot",color=color.yellow)

//hikenashi candle 
ha_t = ticker.heikinashi(syminfo.tickerid)
ha_open = request.security(ha_t, timeframe.period, open)
ha_high = request.security(ha_t, timeframe.period, high)
ha_low = request.security(ha_t, timeframe.period, low)
ha_close = request.security(ha_t, timeframe.period, close)

//green and red candle 
green_candle=(ha_close[1] > ha_open[1])
red_candle=(ha_close [1] < ha_open[1])

sma_buy1=ta.crossover(ha_close,sma_h)  and red_candle
sma_sell1=ta.crossunder(ha_close,sma_l) and green_candle

plotshape(sma_buy1,"Buy Cond",shape.arrowup,location.belowbar,color.green,size=size.normal,text="Buy Signal",textcolor=color.white)
plotshape(sma_sell1,"Sell Cond",shape.arrowdown,location.abovebar,color.red,size=size.normal,text="Sell Signal",textcolor=color.white)

// when previous candle is green and previous before red 
green_candle2=(ha_close[2] > ha_open[2])
red_candle2=(ha_close [2] < ha_open[2])


sma_buy2=ta.crossover(ha_close,sma_h) and green_candle and red_candle2
sma_sell2=ta.crossunder(ha_close,sma_l) and red_candle and green_candle2


plotshape(sma_buy2,"Buy Cond2",shape.triangleup,location.belowbar,color.green,size=size.normal,text="Buy Signal2",textcolor=color.green)
plotshape(sma_sell2,"Sell Cond2",shape.triangledown,location.abovebar,color.red,size=size.normal,text="Sell Signal2",textcolor=color.red)


alertcondition(sma_buy1 or sma_buy2,title ="Buy Signal",message ="Buy1 or Buy2 condition mat")
alertcondition(sma_sell1 or sma_sell2,title ="Sell Signal",message ="Sell1 or Sell2 condition mat")

alertcondition(sma_buy1 or sma_buy2 or sma_sell1 or sma_sell2,title ="Combined Signal",message ="Buy1 or Buy2 or Sell1 or Sell2  condition mat")
