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.")
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.