Pullback Indicator Trial
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Eterna9271

//@version=5
indicator("Pullback Indicator Trial", overlay = true)
//Inputs
fastEmaLength = input(defval = 9, title = 'Fast EMA Length')
slowEmaLength = input(defval = 13, title = 'Slow EMA Length')
slowerEmaLength = input(defval = 21, title = 'Slower EMA Length')
slowestEmaLength = input(defval = 200, title = 'Slowest EMA Length')
atrPeriod = input(defval = 14, title = 'Atr Period')
stoploss = input(defval = 1, title = 'Stoploss')
rr = input(defval = 2, title = 'Risk/Reward Ratio')
showdef = input(defval = true, title = 'Use Default Signals?')
useCandleFilter = input(defval = true, title = 'Use Candle?')

//CALC
highestHigh = ta.highest(high, 6)
lowestLow = ta.lowest(low, 6)

atr = ta.atr(atrPeriod)
bema = ta.ema(low, 1)
sema = ta.ema(high, 1)
fastEma = ta.ema(close, fastEmaLength)
slowEma = ta.ema(close, slowEmaLength)
slowestEma = ta.ema(close, slowerEmaLength)
superslowestEma = ta.ema(close, slowestEmaLength)

//Signal
buySignal = ta.crossunder(bema, fastEma) and fastEma > slowEma and slowEma > slowestEma and slowestEma > superslowestEma and showdef
sellSignal = ta.crossover(sema, fastEma) and fastEma < slowEma and slowEma < slowestEma and slowestEma < superslowestEma and showdef
buyCondition = fastEma > slowEma and slowEma > slowestEma and slowestEma > superslowestEma
sellCondition = fastEma < slowEma and slowEma < slowestEma and slowestEma < superslowestEma


// Get SL and Target prices
EntryPrice = 0.0 
StopPrice = 0.0
TargetPrice = 0.0
buyEntryPrice = highestHigh
sellEntryPrice = lowestLow

// Buy Stoploss and Target
if buySignal 
    StopPrice := buyEntryPrice - ((buyEntryPrice - low) + (stoploss*atr))
    TargetPrice := buyEntryPrice + (rr*((buyEntryPrice - low) + (stoploss*atr))) 
    EntryPrice := buyEntryPrice
    
// Sell Stoploss & Target
if sellSignal 
    StopPrice := sellEntryPrice + ((high - sellEntryPrice) + (stoploss*atr))
    TargetPrice := sellEntryPrice - (rr*((high - sellEntryPrice) + (stoploss*atr))) 
    EntryPrice := sellEntryPrice

// Plot Signal
plotshape(buySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(sellSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)

// Draw stops & targets
plot(buySignal or buySignal[1] ? buySignal ? StopPrice : StopPrice[1] : na, title="Buy Stop Price", color=color.yellow, style=plot.style_linebr)
plot(sellSignal or sellSignal[1] ? sellSignal ? StopPrice : StopPrice[1] : na, title="Sell Stop Price", color=color.yellow, style=plot.style_linebr)
plot(buySignal or buySignal[1] ? buySignal ? TargetPrice : TargetPrice[1] : na, title="Buy Target Price", color=color.blue, style=plot.style_linebr)
plot(sellSignal or sellSignal[1] ? sellSignal ? TargetPrice : TargetPrice[1] : na, title="Sell Target Price", color=color.blue, style=plot.style_linebr)
plot(buySignal or buySignal[1] ? buySignal ? EntryPrice : EntryPrice[1] : na, title="Buy Entry Price", color=color.white, style=plot.style_linebr)
plot(sellSignal or sellSignal[1] ? sellSignal ? EntryPrice : EntryPrice[1] : na, title="Sell Entry Price", color=color.white, style=plot.style_linebr)


//alerts
if buySignal
    alert("Buy Entry (" + str.tostring(highestHigh) + "), StopLoss (" + str.tostring(buyEntryPrice - ((buyEntryPrice - low) + (stoploss*atr))) +  "), TakeProfit (" + str.tostring(buyEntryPrice + (rr*((buyEntryPrice - low) + (stoploss*atr)))) +  ").", alert.freq_once_per_bar_close)
if sellSignal
    alert("Sell Entry (" + str.tostring(lowestLow) + "), StopLoss (" + str.tostring(sellEntryPrice + ((high - sellEntryPrice) + (stoploss*atr))) +  "), TakeProfit (" + str.tostring(sellEntryPrice - (rr*((high - sellEntryPrice) + (stoploss*atr)))) +  ").", alert.freq_once_per_bar_close)