//@version=5
indicator("Zen Open CSC Bars V9", overlay=true)
// === INPUTS ===
numBarsToCheck = input.int(2, "Bars to Check", minval=2, maxval=9)
showLabels = input.bool(true, "Show Bull/Bear Labels")
showSpikeLabel = input.bool(true, "Show Spike Label on Chart", group="Display")
colourBars = input.bool(true, "Colour Bars")
lookbackPeriod = input.int(8, "ABR Lookback Period", minval=1)
// EMA Settings
showEMA20 = input.bool(true, "Show 20 EMA", group="EMAs")
showEMA200 = input.bool(true, "Show 200 EMA", group="EMAs")
// Alert Settings
alertOnClose = input.bool(true, "Alert on Bar Close Only", group="Alerts", tooltip="Recommended ON to avoid repainting alerts intrabar")
// === NEW DAY DETECTION ===
new_day = ta.change(time("D")) != 0
bars_since_new_day = ta.barssince(new_day)
in_session = bars_since_new_day >= 0
// === BAR TYPE ===
is_bull = close > open
is_bear = close < open
// === BAR RANGE CALCULATIONS ===
bar_range = high - low
averageBarRange = ta.sma(bar_range, lookbackPeriod)
barRangeMultiple = averageBarRange > 0 ? bar_range / averageBarRange : 0
// === CSC COUNTING ===
var int bullishBars = 0
var int bearishBars = 0
if new_day
bullishBars := 0
bearishBars := 0
if bars_since_new_day < numBarsToCheck and is_bull
bullishBars += 1
if bars_since_new_day < numBarsToCheck and is_bear
bearishBars += 1
// === DETECTION CONDITIONS ===
bullCSC = bullishBars == numBarsToCheck and bars_since_new_day == numBarsToCheck - 1
bearCSC = bearishBars == numBarsToCheck and bars_since_new_day == numBarsToCheck - 1
// === LABELS ===
symbol_size = size.large
if showLabels
if bullCSC
label.new(bar_index, high, "🟢", color=color.green, size=symbol_size, textcolor=color.white, style=label.style_label_down, yloc=yloc.abovebar)
if bearCSC
label.new(bar_index, high, "🔴", color=color.red, size=symbol_size, textcolor=color.white, style=label.style_label_down, yloc=yloc.abovebar)
// === BAR COLOURING ===
color barcolour = na
if colourBars
barcolour := bullishBars == numBarsToCheck and bars_since_new_day < numBarsToCheck ? color.green :
bearishBars == numBarsToCheck and bars_since_new_day < numBarsToCheck ? color.red : na
barcolor(barcolour)
// === ALERTCONDITIONS (manual alert creation in TV UI) ===
alertcondition(bullCSC, title="Bullish CSC Detected", message="Bullish CSC pattern detected on {{ticker}} {{interval}} at {{close}}")
alertcondition(bearCSC, title="Bearish CSC Detected", message="Bearish CSC pattern detected on {{ticker}} {{interval}} at {{close}}")
alertcondition(bullCSC or bearCSC, title="Any CSC Detected", message="CSC pattern detected on {{ticker}} {{interval}} at {{close}}")
// === DYNAMIC ALERT() CALLS (fires on "Any alert() function call") ===
alertTrigger = alertOnClose ? barstate.isconfirmed : true
if bullCSC and alertTrigger
alert("🟢 Bullish CSC on " + syminfo.ticker + " " + timeframe.period + " @ " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
if bearCSC and alertTrigger
alert("🔴 Bearish CSC on " + syminfo.ticker + " " + timeframe.period + " @ " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
// === TOTAL SPIKE LOGIC (ALL CONSECUTIVE BARS) ===
var int streakLength = 0
var float spikeHigh = na
var float spikeLow = na
var bool spikePrinted = false
var bool isBullStreak = na
var float currentTotalSpikeSize = na
var bool spikeCalculated = false
if new_day
streakLength := 0
spikeHigh := na
spikeLow := na
spikePrinted := false
isBullStreak := na
currentTotalSpikeSize := na
spikeCalculated := false
if in_session and not spikeCalculated
currentBull = is_bull
currentBear = is_bear
continuing = na(isBullStreak) ? true : (isBullStreak ? currentBull : currentBear)
if continuing
streakLength += 1
spikeHigh := na(spikeHigh) ? high : math.max(spikeHigh, high)
spikeLow := na(spikeLow) ? low : math.min(spikeLow, low)
if na(isBullStreak)
isBullStreak := currentBull ? true : false
else
if streakLength >= numBarsToCheck
spikeRange = spikeHigh - spikeLow
currentTotalSpikeSize := spikeRange
spikeCalculated := true
if showSpikeLabel and not spikePrinted
label.new(bar_index[1], spikeHigh, "Total Spike: " + str.tostring(spikeRange, format.mintick), style=label.style_label_down, textcolor=color.black, color=color.new(color.white, 100), size=size.normal)
spikePrinted := true
// === CONSECUTIVE SPIKE (FIRST 2 BARS ONLY) ===
var float bar1High = na
var float bar1Low = na
var float bar2High = na
var float bar2Low = na
var float consecutiveSpikeSize = na
if new_day
bar1High := na
bar1Low := na
bar2High := na
bar2Low := na
consecutiveSpikeSize := na
if bars_since_new_day == 0
bar1High := high
bar1Low := low
if bars_since_new_day == 1
bar2High := high
bar2Low := low
consecSpikeHigh = math.max(bar1High, bar2High)
consecSpikeLow = math.min(bar1Low, bar2Low)
consecutiveSpikeSize := consecSpikeHigh - consecSpikeLow
// === EMAs ===
ema20 = ta.ema(close, 20)
ema200 = ta.ema(close, 200)
plot(showEMA20 ? ema20 : na, "EMA 20", color=color.blue, linewidth=2)
plot(showEMA200 ? ema200 : na, "EMA 200", color=color.red, linewidth=2)
// === DATA WINDOW PLOTS ===
cscBarType = bullishBars == numBarsToCheck and bars_since_new_day < numBarsToCheck ? 1 :
bearishBars == numBarsToCheck and bars_since_new_day < numBarsToCheck ? -1 : 0
totalSpikeSize = not na(currentTotalSpikeSize) ? currentTotalSpikeSize : 0
consecSpikeSize = not na(consecutiveSpikeSize) ? consecutiveSpikeSize : 0
plot(cscBarType, "CSC Bar Type", color=color.new(color.blue, 100), display=display.data_window)
plot(totalSpikeSize, "Total Spike (pts)", color=color.new(color.orange, 100), display=display.data_window)
plot(consecSpikeSize, "Consecutive Spike (pts)", color=color.new(color.purple, 100), display=display.data_window)
plot(bar_range, "Bar Range", color=color.new(color.gray, 100), display=display.data_window)
plot(averageBarRange, "ABR (8)", color=color.new(color.yellow, 100), display=display.data_window)
plot(barRangeMultiple, "Range Multiple", color=color.new(color.green, 100), display=display.data_window)
plot(ema20, "EMA 20", color=color.new(color.blue, 100), display=display.data_window)
plot(ema200, "EMA 200", color=color.new(color.red, 100), display=display.data_window)
Overview
Zen Open CSC Bars counts the first user-set bars after a new day and labels a bullish or bearish CSC when every bar closes in that direction. Settings toggle bar colours, bull and bear labels, a spike label, and 20-period and 200-period EMAs. An average bar range lookback supports range comparison. Alerts can require a confirmed bar; if that filter is off, the live bar can change the signal.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Bars to Check
int
2
numBarsToCheck
Show Bull/Bear Labels
bool
true
showLabels
Show Spike Label on Chart
bool
true
showSpikeLabel
Colour Bars
bool
true
colourBars
ABR Lookback Period
int
8
lookbackPeriod
Show 20 EMA
bool
true
showEMA20
Show 200 EMA
bool
true
showEMA200
Alert on Bar Close Only
bool
true
alertOnClose
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This overlay indicator highlights candles with a body smaller than 50% of their total range by coloring them white on the price chart. Simultaneously, it calculates and plots horizontal lines for open prices across multiple higher timeframes, such as daily, we
Point-Clip Unified Indicator plots breakout and directional labels on the price chart. It scores volume spikes against a volume average, range or opening-range breaks, optional VWAP or session-anchored VWAP, fast and slow EMA trend, and a higher-timeframe EMA
Multi-Ticker Anchored Candles overlays up to three user-selected symbols on the price chart as candles anchored to a chosen period, which defaults to the daily timeframe. Each symbol has its own color and an on or off toggle. Optional drawings mark session bre
This indicator detects three-candle time patterns on the price chart, tracking range, manipulation, and distribution phases based on Smart Money Concepts. It establishes high and low boundaries from the opening candle and identifies boundary rejections during
This indicator plots key session-based price action reference levels on the price chart. It calculates and displays the current session open, previous day close, Globex session high and low, weekly open, and higher-timeframe boundaries. It also supports bar co
TradeKit is an all-in-one technical analysis indicator that consolidates multiple chart overlays into a single script on the price chart. It plots up to four customizable moving averages (SMA, EMA, SMMA, WMA, or VWMA), Bollinger Bands, VWAP, and reference leve