Simple Buy Sell Signals
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mayurssupe

//@version=5
indicator("Simple Buy Sell Signals",overlay=true,format=format.price,shorttitle="SBS")

//RSI Setting
sbs = input.bool(defval = true,title = "Default Signals",group = "Options")
_hide = input.bool(defval=true,title="Lines",group = "Options")
_fastPeriod = input.int(defval = 13,title = "Fast Period",group = "Moving Averages")
_slowPeriod = input.int(defval = 21,title = "slow Period",group = "Moving Averages")

//Green / Red Candle
greenbar = close > open
redbar = close < open

//BB Average Line
var int line_wid = 3
            
fsec(tf,exp) => request.security(ticker.heikinashi(syminfo.tickerid) , tf , exp)
funcWith(tf,exp) => request.security(syminfo.tickerid , tf , exp)


ma1 = funcWith("",math.avg(ta.ema(hlc3,_fastPeriod),ta.ema(hlc3,_fastPeriod)))
ma2 = funcWith("",ta.ema(hlc3,_slowPeriod))

// plot(ma1,color=color.green)
// plot(ma2,color=color.orange)


nmL = ta.crossover(ma1,ma2) and ma1 > ma2 and sbs and volume[1] > volume
nmS = ta.crossunder(ma1,ma2) and ma2 > ma1  and sbs and volume[1] > volume

// if(nmL)
//     strategy.entry("Long",strategy.long)
//     strategy.exit("exit","Short",profit = 1000,loss = 500)

// if(nmS)
//     strategy.entry("Short",strategy.short)
//     strategy.exit("exit","Long",profit = 1000,loss = 500)
    

has_long = nmL[1] ? 1 : 0
has_short = nmS[1] ? 1 : 0

barup = _hide ? ta.valuewhen(has_long,bar_index,0) : na
barHigh = _hide ?  ta.valuewhen(has_long,high,0): na

bardown = _hide ?  ta.valuewhen(has_short,bar_index,0): na
barLow =_hide ? ta.valuewhen(has_short,low,0): na

l1= line.new(barup,barHigh,barup + 1 ,barHigh,color=color.rgb(40, 255, 47,50),extend=extend.right,width=3,style=line.style_solid)
line.delete(l1[1])

l2= line.new(bardown,barLow,bardown + 1 ,barLow,color=color.rgb(255, 1, 77,50),extend=extend.right,width=3,style=line.style_solid)
line.delete(l2[1])

plotshape(nmL[1] ? nmL[1] : 0,title="Long",style=shape.labelup,text="Buy",textcolor=color.white,color=color.aqua,location=location.belowbar)
plotshape(nmS[1] ? nmS[1] : 0,title="Short",style=shape.labeldown,text="Sell",textcolor=color.white,color=color.orange,location=location.abovebar)


