Indicator · Pine Script v6 · Own pane

Change of Context

by ElroyvOuwerkerk· code credited to elroyvanouwerkerk

A candle-pair indicator that marks a bearish signal when a bar fails to take the previous high and closes below the previous low, and a bullish signal in the mirror case.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code134
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update7 days ago22 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

134 lines of Pine Script v6 from indicators/change-of-context.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

change-of-context.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © elroyvanouwerkerk

//@version=6
indicator("My script")
plot(close)
//@version=6
indicator("Change of Context", shorttitle="Change of Context", overlay=true, max_labels_count=500)

// ===== Symbols & Inputs (similar to Cherry on Top) =====
// Bearish marker settings
bearSym = input.string("▼", "Bearish Symbol", options = ["▼","▲","★","●","◆","■","✖","✚"])
bearCol = input.color(color.new(color.red, 0), "Bearish Symbol Color")
bearLoc = input.string("Above bar", "Bearish Symbol Location", options = ["Above bar", "Below bar"])

// Bullish marker settings
bullSym = input.string("▲", "Bullish Symbol", options = ["▲","▼","★","●","◆","■","✖","✚"])
bullCol = input.color(color.new(color.lime, 0), "Bullish Symbol Color")
bullLoc = input.string("Below bar", "Bullish Symbol Location", options = ["Above bar", "Below bar"])

// Marker size (use const size enums via gated calls)
sizeOpt     = input.string("Small", "Marker Size", options = ["Tiny","Small","Normal","Large","Very Large"])
isTiny      = sizeOpt == "Tiny"
isSmall     = sizeOpt == "Small"
isNormal    = sizeOpt == "Normal"
isLarge     = sizeOpt == "Large"
isVeryLarge = sizeOpt == "Very Large"

// ===== Optional Divisions Filter =====
useDivisions = input.bool(false, "Use Divisions Filter", tooltip="When enabled, Candle 2 must also close in the lower division (bearish) or upper division (bullish) of its own range.")
divOpt       = input.string("4", "Number of Divisions", options = ["2","3","4","5","6","8","10"])
divisions    = int(str.tonumber(divOpt))
divF         = float(divisions)

// Resolve locations
bearAbove = bearLoc == "Above bar"
bullAbove = bullLoc == "Above bar"

// ===== Thresholds (per current bar, for divisions filter) =====
rng      = high - low
lowerTh  = low + rng * (1.0 / divF)           // Lower division threshold (1/div)
upperTh  = low + rng * ((divF - 1.0) / divF)  // Upper division threshold ((div-1)/div)

// ===== Base Signals (Change of Context rules) =====
// Bearish: Candle 2 does NOT take Candle 1 high AND closes below Candle 1 low
baseBearish = (high <= high[1]) and (close < low[1])
// Bullish: Candle 2 does NOT take Candle 1 low AND closes above Candle 1 high
baseBullish = (low >= low[1]) and (close > high[1])

// Apply optional divisions filter
bearDivOK = (rng > 0) and (close <= lowerTh)
bullDivOK = (rng > 0) and (close >= upperTh)

bearishSignal = baseBearish and (not useDivisions or bearDivOK)
bullishSignal = baseBullish and (not useDivisions or bullDivOK)

// ===== Draw labels (no Style tab entries) =====
bgNone = color.new(color.white, 100)

// Bearish Above
if bearishSignal and bearAbove and isTiny
    label.new(bar_index, high, text=bearSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.tiny, textalign=text.align_center)
if bearishSignal and bearAbove and isSmall
    label.new(bar_index, high, text=bearSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.small, textalign=text.align_center)
if bearishSignal and bearAbove and isNormal
    label.new(bar_index, high, text=bearSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.normal, textalign=text.align_center)
if bearishSignal and bearAbove and isLarge
    label.new(bar_index, high, text=bearSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.large, textalign=text.align_center)
if bearishSignal and bearAbove and isVeryLarge
    label.new(bar_index, high, text=bearSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.huge, textalign=text.align_center)

// Bearish Below
if bearishSignal and not bearAbove and isTiny
    label.new(bar_index, low, text=bearSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.tiny, textalign=text.align_center)
if bearishSignal and not bearAbove and isSmall
    label.new(bar_index, low, text=bearSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.small, textalign=text.align_center)
if bearishSignal and not bearAbove and isNormal
    label.new(bar_index, low, text=bearSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.normal, textalign=text.align_center)
if bearishSignal and not bearAbove and isLarge
    label.new(bar_index, low, text=bearSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.large, textalign=text.align_center)
if bearishSignal and not bearAbove and isVeryLarge
    label.new(bar_index, low, text=bearSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bearCol, size=size.huge, textalign=text.align_center)

// Bullish Above
if bullishSignal and bullAbove and isTiny
    label.new(bar_index, high, text=bullSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.tiny, textalign=text.align_center)
if bullishSignal and bullAbove and isSmall
    label.new(bar_index, high, text=bullSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.small, textalign=text.align_center)
if bullishSignal and bullAbove and isNormal
    label.new(bar_index, high, text=bullSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.normal, textalign=text.align_center)
if bullishSignal and bullAbove and isLarge
    label.new(bar_index, high, text=bullSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.large, textalign=text.align_center)
if bullishSignal and bullAbove and isVeryLarge
    label.new(bar_index, high, text=bullSym, xloc=xloc.bar_index, yloc=yloc.abovebar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.huge, textalign=text.align_center)

// Bullish Below
if bullishSignal and not bullAbove and isTiny
    label.new(bar_index, low, text=bullSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.tiny, textalign=text.align_center)
if bullishSignal and not bullAbove and isSmall
    label.new(bar_index, low, text=bullSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.small, textalign=text.align_center)
if bullishSignal and not bullAbove and isNormal
    label.new(bar_index, low, text=bullSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.normal, textalign=text.align_center)
if bullishSignal and not bullAbove and isLarge
    label.new(bar_index, low, text=bullSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.large, textalign=text.align_center)
if bullishSignal and not bullAbove and isVeryLarge
    label.new(bar_index, low, text=bullSym, xloc=xloc.bar_index, yloc=yloc.belowbar,
        style=label.style_none, color=bgNone, textcolor=bullCol, size=size.huge, textalign=text.align_center)

// ===== Alerts (const strings only) =====
// Bearish alerts
alertcondition(bearishSignal and not useDivisions, title="Change of Context - Bearish", message="Bearish Change of Context: No HH and close < previous low")
alertcondition(bearishSignal and useDivisions,     title="Change of Context - Bearish (Divisions)", message="Bearish Change of Context: No HH and close < previous low + lower division filter")
// Bullish alerts
alertcondition(bullishSignal and not useDivisions, title="Change of Context - Bullish", message="Bullish Change of Context: No LL and close > previous high")
alertcondition(bullishSignal and useDivisions,     title="Change of Context - Bullish (Divisions)", message="Bullish Change of Context: No LL and close > previous high + upper division filter")

Overview

An optional divisions filter also requires the close to sit in the lower or upper fraction of the bar's range, with 2 to 10 divisions. Marker symbol, colour, position and size are adjustable. It draws labels on the price chart. It issues no stop, target or exit rules.

Details

Published by

ElroyvOuwerkerk on GitHub

Code credit

elroyvanouwerkerk, as written in the script's header

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

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

SettingTypeDefaultVariable
Bearish Symbolstring▼bearSym
Bearish Symbol Colorcolorcolor.new(color.red, 0)bearCol
Bearish Symbol LocationstringAbove barbearLoc
Bullish Symbolstring▲bullSym
Bullish Symbol Colorcolorcolor.new(color.lime, 0)bullCol
Bullish Symbol LocationstringBelow barbullLoc
Marker SizestringSmallsizeOpt
Use Divisions FilterboolfalseuseDivisions
Number of Divisionsstring4divOpt
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

The Bullish/Bearish Candle Series Distribution indicator calculates the length of the current streak of consecutive bullish or bearish candles based on user-selected mode. It tracks streak lengths from 2 to 59 and plots a histogram in a separate pane showing t

Indicator v4 Candlestick patterns
Updated 11 days ago · GPL-3.0 GitHub repository of Bullish/Bearish Candle Series Distribution

My Script

by ricardosantos79
261 stars

This indicator plots a normalized candle dynamic visualization inside a custom 500x500 Gann square grid within a separate pane. It normalizes each bar's open and close prices relative to its high-low range, storing the resulting coordinate pairs in fixed-size

Indicator v5 Support & resistanceCandlestick patterns
Updated 4 years ago · None stated GitHub repository of My Script

Commitment Gauge

by harryguiacorn
220 stars

This indicator measures directional momentum by evaluating candlestick body proportions and volume over a user-defined lookback window. It computes the ratio of candle body to total range, weights the cumulative value by volume and absolute body size, and dete

Indicator v4 VolumeCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Commitment Gauge

Qstick Indicator

by mihakralj
99 stars

This indicator calculates the Qstick value as a simple or exponential moving average of the difference between a chosen close source and open source. It plots that oscillator in a separate pane as a yellow line, draws a dashed zero line, and shades the backgro

Indicator v6 Oscillators & momentumCandlestick patterns
Updated 4 weeks ago · Apache-2.0 GitHub repository of Qstick Indicator

Dual-color bars

by be-thomas
65 stars

This indicator draws a separate OHLC bar series in its own pane using plotbar. Each bar is colored lime when the close is greater than or equal to the open, and red when the close is below the open. It has no user inputs, no signals, and no entry, exit, stop,

Indicator v5 Candlestick patterns
Updated 5 days ago · GPL-3.0 GitHub repository of Dual-color bars
43 stars

This indicator builds a synthetic Heikin-Ashi series using only the current open and the opens of the previous three bars. It derives open, high, low, and close from those values, rounds each price to the symbol mintick, and plots the result as candles in a se

Indicator v5 Candlestick patterns
Updated 2 years ago · None stated GitHub repository of Heikin-Ashi Open Only

More Candlestick patterns scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers