Indicator · Pine Script v5 · On the chart

Zen Open CSC Bars

by Zen-Tim

This indicator marks consecutive same-direction candles at the start of each daily session.

View on GitHub

Repaints

GitHub stars29on the repository
Pine versionv5runs as is
Lines of code164
Settings8inputs
LicenceMIT
Last update2 weeks ago14 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

164 lines of Pine Script v5 from indicators/Zen-Open-CSC-Bars/zen-open-csc-bars-v9.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

zen-open-csc-bars-v9.txt
//@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.

Details

Published by

Zen-Tim on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, Sessions & time

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Bars to Checkint2numBarsToCheck
Show Bull/Bear LabelsbooltrueshowLabels
Show Spike Label on ChartbooltrueshowSpikeLabel
Colour BarsbooltruecolourBars
ABR Lookback Periodint8lookbackPeriod
Show 20 EMAbooltrueshowEMA20
Show 200 EMAbooltrueshowEMA200
Alert on Bar Close OnlybooltruealertOnClose
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.

Similar Pine Scripts

56 stars

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

Indicator v6 Support & resistanceCandlestick patterns Repaints
Updated 2 months ago · None stated GitHub repository of Daily Weekly Monthly Yearly Opens
23 stars

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

Indicator v6 BreakoutVolume Repaints
Updated 3 weeks ago · Custom licence GitHub repository of Point-Clip Unified Indicator
7 stars

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

Indicator v6 Candlestick patternsSessions & time
Updated 3 months ago · None stated GitHub repository of Multi-Ticker Anchored Candles

3-Candle Time Pattern

by alboogycOdR
6 stars

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

Indicator v5 SMC / ICT / price actionCandlestick patterns
Updated 7 months ago · None stated GitHub repository of 3-Candle Time Pattern

BPA [yohtza]

by forecho
5 stars

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

Indicator v6 Sessions & timeSupport & resistance
Updated 8 weeks ago · None stated GitHub repository of BPA [yohtza]

TradeKit

by tanishq-rocks
5 stars

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

Indicator v6 Moving averagesCandlestick patterns
Updated 3 months ago · MPL-2.0 GitHub repository of TradeKit

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers