OPEN-SOURCE SCRIPT
Daily Put Spread Signals - Final Clean v5

//version=5
indicator("Daily Put Spread Signals - Final Clean v5", overlay=true)
//========================
// Inputs
//========================
ma20Len = input.int(20, "MA20 Length")
ma50Len = input.int(50, "MA50 Length")
ma200Len = input.int(200, "MA200 Length")
pullbackPct = input.float(0.01, "Pullback proximity to MA20 (1% = 0.01)", step=0.005)
minRedDays = input.int(1, "Min red days in last 5 bars (0-5)", minval=0, maxval=5)
stopBelow200Pct = input.float(0.005, "STOP: Close below MA200 by % (0.5%=0.005)", step=0.0025)
//========================
// Moving averages
//========================
ma20 = ta.sma(close, ma20Len)
ma50 = ta.sma(close, ma50Len)
ma200 = ta.sma(close, ma200Len)
//========================
// Trend filter (bull regime)
//========================
bullTrend = close > ma50 and close > ma200 and ma50 > ma200
//========================
// Pullback condition (near MA20)
//========================
nearMA20 = close <= ma20 * (1 + pullbackPct)
//========================
// Count red candles in last 5 bars (NO ta.sum)
//========================
isRed(barBack) => close[barBack] < open[barBack] ? 1 : 0
redCount = isRed(0) + isRed(1) + isRed(2) + isRed(3) + isRed(4)
hasMinRed = redCount >= minRedDays
//========================
// Bounce confirmation
//========================
bounce = close > open and close > close[1]
//========================
// Entry signal
//========================
enter = bullTrend and nearMA20 and hasMinRed and bounce
//========================
// Exit signals
//========================
takeProfit = ta.crossover(close, ma20)
stopOut = close < ma200 * (1 - stopBelow200Pct)
//========================
// Plots
//========================
plot(ma20, "MA20", linewidth=2)
plot(ma50, "MA50", linewidth=2)
plot(ma200, "MA200", linewidth=2)
plotshape(enter, title="ENTER", style=shape.labelup, location=location.belowbar, text="ENTER\nSell Put Vertical", size=size.small)
plotshape(takeProfit, title="EXIT TP", style=shape.labeldown, location=location.abovebar, text="EXIT\nTake Profit", size=size.small)
plotshape(stopOut, title="EXIT STOP", style=shape.labeldown, location=location.abovebar, text="EXIT\nSTOP", size=size.small)
//========================
// Alerts
//========================
alertcondition(enter, title="ENTER Alert (Daily)", message="ENTER (Daily): Bull trend + pullback near MA20 + bounce. Consider selling put credit spread (30-45 DTE).")
alertcondition(takeProfit, title="EXIT Take Profit Alert (Daily)", message="EXIT TP (Daily): Price reclaimed MA20. Consider taking profit on put spread.")
alertcondition(stopOut, title="EXIT Stop Alert (Daily)", message="EXIT STOP (Daily): Close below MA200 threshold. Consider closing/rolling defensive.")
indicator("Daily Put Spread Signals - Final Clean v5", overlay=true)
//========================
// Inputs
//========================
ma20Len = input.int(20, "MA20 Length")
ma50Len = input.int(50, "MA50 Length")
ma200Len = input.int(200, "MA200 Length")
pullbackPct = input.float(0.01, "Pullback proximity to MA20 (1% = 0.01)", step=0.005)
minRedDays = input.int(1, "Min red days in last 5 bars (0-5)", minval=0, maxval=5)
stopBelow200Pct = input.float(0.005, "STOP: Close below MA200 by % (0.5%=0.005)", step=0.0025)
//========================
// Moving averages
//========================
ma20 = ta.sma(close, ma20Len)
ma50 = ta.sma(close, ma50Len)
ma200 = ta.sma(close, ma200Len)
//========================
// Trend filter (bull regime)
//========================
bullTrend = close > ma50 and close > ma200 and ma50 > ma200
//========================
// Pullback condition (near MA20)
//========================
nearMA20 = close <= ma20 * (1 + pullbackPct)
//========================
// Count red candles in last 5 bars (NO ta.sum)
//========================
isRed(barBack) => close[barBack] < open[barBack] ? 1 : 0
redCount = isRed(0) + isRed(1) + isRed(2) + isRed(3) + isRed(4)
hasMinRed = redCount >= minRedDays
//========================
// Bounce confirmation
//========================
bounce = close > open and close > close[1]
//========================
// Entry signal
//========================
enter = bullTrend and nearMA20 and hasMinRed and bounce
//========================
// Exit signals
//========================
takeProfit = ta.crossover(close, ma20)
stopOut = close < ma200 * (1 - stopBelow200Pct)
//========================
// Plots
//========================
plot(ma20, "MA20", linewidth=2)
plot(ma50, "MA50", linewidth=2)
plot(ma200, "MA200", linewidth=2)
plotshape(enter, title="ENTER", style=shape.labelup, location=location.belowbar, text="ENTER\nSell Put Vertical", size=size.small)
plotshape(takeProfit, title="EXIT TP", style=shape.labeldown, location=location.abovebar, text="EXIT\nTake Profit", size=size.small)
plotshape(stopOut, title="EXIT STOP", style=shape.labeldown, location=location.abovebar, text="EXIT\nSTOP", size=size.small)
//========================
// Alerts
//========================
alertcondition(enter, title="ENTER Alert (Daily)", message="ENTER (Daily): Bull trend + pullback near MA20 + bounce. Consider selling put credit spread (30-45 DTE).")
alertcondition(takeProfit, title="EXIT Take Profit Alert (Daily)", message="EXIT TP (Daily): Price reclaimed MA20. Consider taking profit on put spread.")
alertcondition(stopOut, title="EXIT Stop Alert (Daily)", message="EXIT STOP (Daily): Close below MA200 threshold. Consider closing/rolling defensive.")
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.