//@version=5 // ===================================================================== // SPX Module 1 — Swing Long // Trend-regime momentum system. Long-only. // // Signals plotted: // • Background colour — regime (StrongUp / StrongDown / Mixed) // • SMAs — 20 / 50 / 200 day // • Yellow ▽ above bar — NR7 (today's range = smallest of last 7) // • Lime ▲ "20MA" — pullback to 20-DMA in StrongUp regime // • Green ▲ "FRI" — Friday close in StrongUp regime // • Aqua ◇ "NR7+" — add half unit after NR7 in regime // • Red ✕ "EXIT" — close below 20-DMA from above // • Orange ✕ "+2%" — single-day +2% move (mean-revert exit) // ===================================================================== indicator("SPX Module 1 — Swing Long", overlay=true, max_labels_count=200) // === Inputs === showSMAs = input.bool(true, "Show SMAs (20 / 50 / 200)") showRegimeBG = input.bool(true, "Tint background by regime") showNR7 = input.bool(true, "Mark NR7 days") showEntries = input.bool(true, "Show entry signals") showExits = input.bool(true, "Show exit signals") // === Regime === sma20 = ta.sma(close, 20) sma50 = ta.sma(close, 50) sma200 = ta.sma(close, 200) aboveAll = close > sma20 and close > sma50 and close > sma200 belowAll = close < sma20 and close < sma50 and close < sma200 mixed = not aboveAll and not belowAll regimeColor = aboveAll ? color.new(color.green, 92) : belowAll ? color.new(color.red, 92) : color.new(color.gray, 95) bgcolor(showRegimeBG ? regimeColor : na, title="Regime") // === SMA plots === plot(showSMAs ? sma20 : na, "SMA20", color=color.new(color.aqua, 0), linewidth=2) plot(showSMAs ? sma50 : na, "SMA50", color=color.new(color.orange, 0), linewidth=2) plot(showSMAs ? sma200 : na, "SMA200", color=color.new(color.purple, 0), linewidth=2) // === NR7 === todayRange = high - low nr7 = todayRange == ta.lowest(todayRange, 7) plotshape(showNR7 and nr7, title="NR7", style=shape.triangledown, location=location.abovebar, color=color.new(color.yellow, 0), size=size.tiny) // === Entry signals === // (1) Pullback to 20-DMA inside StrongUp regime pullbackLong = aboveAll and low <= sma20 and close > sma20 plotshape(showEntries and pullbackLong, title="20-DMA Pullback Long", style=shape.triangleup, location=location.belowbar, color=color.new(color.lime, 0), size=size.small, text="20MA") // (2) Friday close in StrongUp isFriday = dayofweek == dayofweek.friday fridayLong = aboveAll and isFriday and barstate.isconfirmed plotshape(showEntries and fridayLong, title="Friday StrongUp Long", style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.small, text="FRI") // (3) Add half-unit after NR7 in regime addAfterNR7 = aboveAll and nr7 plotshape(showEntries and addAfterNR7, title="Add after NR7", style=shape.diamond, location=location.belowbar, color=color.new(color.aqua, 0), size=size.tiny, text="NR7+") // === Exit signals === exitBelow20 = close < sma20 and close[1] >= sma20[1] plotshape(showExits and exitBelow20, title="Exit: close < 20-DMA", style=shape.xcross, location=location.abovebar, color=color.new(color.red, 0), size=size.small, text="EXIT") ret = (close - close[1]) / close[1] * 100 bigUp = ret > 2.0 plotshape(showExits and bigUp, title="Exit: +2% day", style=shape.xcross, location=location.abovebar, color=color.new(color.orange, 0), size=size.small, text="+2%") // === Status label on most recent bar === var label statusLbl = na if barstate.islast label.delete(statusLbl) regimeStr = aboveAll ? "STRONG UP" : belowAll ? "STRONG DOWN" : "MIXED" qualifier = nr7 ? " | NR7" : "" statusLbl := label.new(bar_index, high, text="Module 1 — " + regimeStr + qualifier, style=label.style_label_down, color=color.new(color.black, 20), textcolor=color.white, size=size.normal) // === Alerts === alertcondition(pullbackLong, "M1: 20-DMA Pullback Long", "M1: SPX touched 20-DMA in StrongUp — long entry") alertcondition(fridayLong, "M1: Friday StrongUp Long", "M1: Friday close in StrongUp — long entry") alertcondition(addAfterNR7, "M1: Add after NR7", "M1: NR7 in regime — add half unit") alertcondition(exitBelow20, "M1: Exit below 20-DMA", "M1: Close below 20-DMA — exit long") alertcondition(bigUp, "M1: Exit +2% day", "M1: +2% single-day — mean-revert exit")