Pocket Pivot, Darvas Box, EMA
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Krishna216
//@version=5
indicator("Pocket Pivot, Darvas Box, EMA", shorttitle="PPDBEMA", overlay=true)

// EMA
emaLength = input(20,title = "EMA Length")
emaValue = ta.ema(close, emaLength)


// Pocket Pivot Condition
ppCondition = close > emaValue and close > close[1] and close[1] > ta.ema(close[1],emaLength)

// Darvas Box Condition
boxCondition = low > low[1] and high < high[1]

// Plotting conditions
plotshape(ppCondition, title="Pocket Pivot", color=color.green, style=shape.triangleup, location=location.belowbar, size=size.small)
bgcolor(boxCondition ? color.new(color.blue, 90) : na, title="Darvas Box", offset=-1)

plot(emaValue, title="EMA", color=color.orange, linewidth=2)

// Plot Buy and Sell signals for Darvas Box (optional)
boxBuyCondition = boxCondition and close > open
boxSellCondition = boxCondition and close < open

plotshape(boxBuyCondition, title="Box Buy Signal", color=color.green, style=shape.labelup, location=location.belowbar, text="Buy")
plotshape(boxSellCondition, title="Box Sell Signal", color=color.red, style=shape.labeldown, location=location.abovebar, text="Sell")
