//@version=5
indicator("Buy the Dip Strategy (Any Coin)", overlay=true)
// === INPUTS ===
stochKLen = input.int(14, "Stochastic %K Length")
stochDLen = input.int(3, "Stochastic %D Length")
stochSmooth = input.int(3, "Stochastic Smoothing")
buyZone = input.float(0.98, "Buy Zone % (e.g. 0.98 = 2% below)", step=0.01)
tpMultiplier = input.float(1.05, "Take Profit % (e.g. 1.05 = 5% above)", step=0.01)
slMultiplier = input.float(0.97, "Stop Loss % (e.g. 0.97 = 3% below)", step=0.01)
// === STOCHASTIC OSCILLATOR ===
k = ta.sma(ta.stoch(close, high, low, stochKLen), stochSmooth)
d = ta.sma(k, stochDLen)
// === DYNAMIC LEVELS ===
var float entryPrice = na
var bool inTrade = false
// === BUY CONDITIONS ===
buyCondition = ta.crossover(k, d) and k < 80
if (buyCondition and not inTrade)
entryPrice := close
inTrade := true
// === TP and SL LEVELS ===
takeProfitPrice = entryPrice * tpMultiplier
stopLossPrice = entryPrice * slMultiplier
// === EXIT CONDITIONS ===
exitConditionTP = inTrade and close >= takeProfitPrice
exitConditionSL = inTrade and close <= stopLossPrice
if (exitConditionTP or exitConditionSL)
inTrade := false
entryPrice := na
// === PLOTS ===
plotshape(buyCondition and not inTrade, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(exitConditionTP, title="Take Profit", location=location.abovebar, color=color.red, style=shape.labeldown, text="TP")
plotshape(exitConditionSL, title="Stop Loss", location=location.abovebar, color=color.orange, style=shape.labeldown, text="SL")
plot(entryPrice, title="Entry Price", color=color.new(color.green, 60))
plot(inTrade ? takeProfitPrice : na, title="Take Profit Level", color=color.new(color.red, 60), style=plot.style_line)
plot(inTrade ? stopLossPrice : na, title="Stop Loss Level", color=color.new(color.orange, 60), style=plot.style_line)
#pinescript #Write2Earn