//@version=5

indicator("Strategi Beli Saat Turun (Koin Apa Saja)", overlay=true)

// === INPUT ===

stochKLen = input.int(14, "Panjang Stochastic %K")

stochDLen = input.int(3, "Panjang Stochastic %D")

stochSmooth = input.int(3, "Penyaringan Stochastic")

buyZone = input.float(0.98, "Zona Beli % (mis. 0.98 = 2% di bawah)", step=0.01)

tpMultiplier = input.float(1.05, "Ambil Untung % (mis. 1.05 = 5% di atas)", step=0.01)

slMultiplier = input.float(0.97, "Hentikan Kerugian % (mis. 0.97 = 3% di bawah)", step=0.01)

// === OSCILLATOR STOCHASTIC ===

k = ta.sma(ta.stoch(close, high, low, stochKLen), stochSmooth)

d = ta.sma(k, stochDLen)

// === LEVEL DINAMIS ===

var float entryPrice = na

var bool inTrade = false

// === KONDISI BELI ===

buyCondition = ta.crossover(k, d) and k < 80

if (buyCondition and not inTrade)

entryPrice := close

inTrade := true

// === LEVEL TP dan SL ===

takeProfitPrice = entryPrice * tpMultiplier

stopLossPrice = entryPrice * slMultiplier

// === KONDISI KELUAR ===

exitConditionTP = inTrade and close >= takeProfitPrice

exitConditionSL = inTrade and close <= stopLossPrice

if (exitConditionTP or exitConditionSL)

inTrade := false

entryPrice := na

// === PLOT ===

plotshape(buyCondition and not inTrade, title="Sinyal Beli", location=location.belowbar, color=color.green, style=shape.labelup, text="BELI")

plotshape(exitConditionTP, title="Ambil Untung", location=location.abovebar, color=color.red, style=shape.labeldown, text="TP")

plotshape(exitConditionSL, title="Hentikan Kerugian", location=location.abovebar, color=color.orange, style=shape.labeldown, text="SL")

plot(entryPrice, title="Harga Masuk", color=color.new(color.green, 60))

plot(inTrade ? takeProfitPrice : na, title="Level Ambil Untung", color=color.new(color.red, 60), style=plot.style_line)

plot(inTrade ? stopLossPrice : na, title="Level Hentikan Kerugian", color=color.new(color.orange, 60), style=plot.style_line)

#pinescript #Write2Earn