Indicator · Pine Script v6 · On the chart

Market Structure Confluence [AlgoAlpha]

by theonetrade

Market Structure Confluence [AlgoAlpha] identifies market structure shifts, including Break of Structure (BOS) and Change of Character (CHoCH), by tracking pivot highs and lows on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code133
Settings12inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

133 lines of Pine Script v6 from assets/indicator/bit-exact/market_structure_confluence_algoalpha_wjB7JR9O.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

market_structure_confluence_algoalpha_wjB7JR9O.pine
//@version=6
indicator("Market Structure Confluence [AlgoAlpha]", shorttitle="AlgoAlpha - Market Structure", overlay=true, max_lines_count=500, max_labels_count=500, max_bars_back=5000)

swingSize   = input.int(10,     "Time-Horizon",              minval=2, tooltip="Look-back bars for pivot detection", group="Market Structure")
bosConfType = input.string("Candle Close", "BOS Confirmation", options=["Candle Close", "Wicks"], tooltip="Close vs. wick confirmation", group="Market Structure")
bosStyleIn  = input.string("Solid", "BOS/CHoCH Line Style",  options=["Solid","Dashed","Dotted"], group="Market Structure")
showCHoCH   = input.bool(true,  "Show CHoCH",  group="Market Structure")
showSwing   = input.bool(true,  "Show Swing Labels", group="Market Structure")

basisLength = input.int(100, "Basis Length", minval=1, tooltip="Length for the basis calculation (WMA)", group="Band Settings")
atrLength   = input.int(14, "ATR Length", minval=1, tooltip="Length for the volatility (ATR) calculation", group="Band Settings")
atrSmooth   = input.int(21, "ATR Smoothing", minval=1, tooltip="Length for smoothing the volatility", group="Band Settings")
volMult     = input.float(2.0, "Volatility Multiplier", minval=0.1, step=0.1, tooltip="Multiplier for the bands", group="Band Settings")

colBull     = input.color(#00FFBB, "Bull   Color", inline="msc", group="Appearance")
colBear     = input.color(#FF1100, "Bear   Color", inline="msc", group="Appearance")

waitClose   = input.bool(true, "Wait for Bar Close (alerts)", group="⚠️ Alerts")

bosWidth   = 1
colBull50  = color.new(colBull, 50)
colBear50  = color.new(colBear, 50)
colClear   = color.rgb(0,0,0,100)
barConfirmed = not waitClose or barstate.isconfirmed

lineStyle(string s)=>
    s=="Solid"  ? line.style_solid : s=="Dashed" ? line.style_dashed : line.style_dotted

var float  prevHigh       = na
var float  prevLow        = na
var int    prevHighIdx    = na
var int    prevLowIdx     = na
var bool   highActive     = false
var bool   lowActive      = false
var int    prevBreakDir   = 0
var int    lastBreakDir   = 0
enMS        = true

pivHi = ta.pivothigh(high, swingSize, swingSize)
pivLo = ta.pivotlow (low , swingSize, swingSize)

bool hh = false, lh = false, hl = false, ll = false

if enMS
    if not na(pivHi)
        hh := na(prevHigh) or pivHi >= prevHigh
        lh := not hh
        prevHigh      := pivHi
        prevHighIdx   := bar_index - swingSize
        highActive    := true
    if not na(pivLo)
        hl := na(prevLow) or pivLo >= prevLow
        ll := not hl
        prevLow       := pivLo
        prevLowIdx    := bar_index - swingSize
        lowActive     := true

highSrc = bosConfType=="Candle Close" ? close : high
lowSrc  = bosConfType=="Candle Close" ? close : low

bool highBroken = false, lowBroken=false
if enMS
    if highActive and not na(prevHigh) and highSrc > prevHigh
        highBroken := true
        highActive := false
    if lowActive and not na(prevLow) and lowSrc < prevLow
        lowBroken  := true
        lowActive  := false

volatility = ta.atr(atrLength)
svol = ta.sma(volatility, atrSmooth)

basis = ta.wma(close, basisLength)
upper = basis + volMult * svol
lower = basis - volMult * svol

plot(prevBreakDir == 1 ? lower : na, color = colBull, title="Lower Band", style = plot.style_linebr, linewidth = 3)
plot(prevBreakDir == -1 ? upper : na, color = colBear, title="Upper Band", style = plot.style_linebr, linewidth = 3)

bullishArrow = prevBreakDir == 1 and low < lower and high > lower
bearishArrow = prevBreakDir == -1 and low < upper and high > upper

arrowOffset = volatility * 1

plotchar(bullishArrow ? lower - arrowOffset : na, "Bullish Signal", '▲', location.absolute, colBull, size = size.tiny)
plotchar(bearishArrow ? upper + arrowOffset : na, "Bearish Signal", '▼', location.absolute, colBear, size = size.tiny)

if enMS and showSwing
    if hh
        label.new(bar_index-swingSize, pivHi, "HH", style=label.style_label_down, textcolor=colBull50, color=colClear)
    if lh
        label.new(bar_index-swingSize, pivHi, "LH", style=label.style_label_down, textcolor=colBear50, color=colClear)
    if hl
        label.new(bar_index-swingSize, pivLo, "HL", style=label.style_label_up,   textcolor=colBull50, color=colClear)
    if ll
        label.new(bar_index-swingSize, pivLo, "LL", style=label.style_label_up,   textcolor=colBear50, color=colClear)

bullishChange = false
bearishChange = false

if enMS and highBroken
    line.new(prevHighIdx, prevHigh, bar_index, prevHigh, color=colBull, style=lineStyle(bosStyleIn), width=bosWidth)
    mid   = math.floor(bar_index - (bar_index - prevHighIdx)/2)
    label.new(mid, prevHigh, prevBreakDir==-1 and showCHoCH ? "CHoCH":"BOS", color=colClear, textcolor=colBull, size=size.tiny)
    lastBreakDir := prevBreakDir
    prevBreakDir := 1
    bullishChange := lastBreakDir == -1 or lastBreakDir == 0

if enMS and lowBroken
    line.new(prevLowIdx, prevLow, bar_index, prevLow, color=colBear, style=lineStyle(bosStyleIn), width=bosWidth)
    mid   = math.floor(bar_index - (bar_index - prevLowIdx)/2)
    label.new(mid, prevLow, prevBreakDir==1 and showCHoCH ? "CHoCH":"BOS", style=label.style_label_up, color=colClear, textcolor=colBear, size=size.tiny)
    lastBreakDir := prevBreakDir
    prevBreakDir := -1
    bearishChange := lastBreakDir == 1 or lastBreakDir == 0

plotchar(bullishChange ? lower : na, "Trend Change Bullish", '◉', location.absolute, colBull, size = size.tiny)
plotchar(bearishChange ? upper : na, "Trend Change Bearish", '◉', location.absolute, colBear, size = size.tiny)

barcolor(enMS ? (prevBreakDir==-1 ? color.new(colBear, 30) : color.new(colBull, 30)) : na)

alertcondition(highBroken and prevBreakDir==-1 and barConfirmed, "Bullish CHoCH")
alertcondition(highBroken and prevBreakDir!= -1 and barConfirmed, "Bullish BOS")
alertcondition(lowBroken  and prevBreakDir==1  and barConfirmed, "Bearish CHoCH")
alertcondition(lowBroken  and prevBreakDir!= 1 and barConfirmed, "Bearish BOS")
alertcondition(hh and barConfirmed, "HH Detected")
alertcondition(lh and barConfirmed, "LH Detected")
alertcondition(hl and barConfirmed, "HL Detected")
alertcondition(ll and barConfirmed, "LL Detected")
alertcondition(bullishArrow and barConfirmed, "Bullish Arrow Signal", "Bullish Rejection Signal")
alertcondition(bearishArrow and barConfirmed, "Bearish Arrow Signal", "Bearish Rejection Signal")
alertcondition(bullishChange and barConfirmed, "Bullish Trend Change", "Trend changed to bullish")
alertcondition(bearishChange and barConfirmed, "Bearish Trend Change", "Trend changed to bearish")

Overview

Users can choose between candle close or wick break confirmations and toggle swing point labels. The indicator also plots dynamic volatility bands constructed from a Weighted Moving Average (WMA) and a smoothed Average True Range (ATR) directly on the price chart.

Details

Published by

theonetrade on GitHub

Draws

On the price 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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Time-Horizonint10swingSize
BOS ConfirmationstringCandle ClosebosConfType
BOS/CHoCH Line StylestringSolidbosStyleIn
Show CHoCHbooltrueshowCHoCH
Show Swing LabelsbooltrueshowSwing
Basis Lengthint100basisLength
ATR Lengthint14atrLength
ATR Smoothingint21atrSmooth
Volatility Multiplierfloat2.0volMult
Bull Colorcolor#00FFBBcolBull
Bear Colorcolor#FF1100colBear
Wait for Bar Close (alerts)booltruewaitClose
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

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill
228 stars

This indicator maps market structure and supply and demand zones on the price chart. It marks validated and optional unvalidated swing highs and lows using a pivot length and extra confirmation bars. Consolidation and impulse moves are measured against ATR to

Indicator v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 4 months ago · None stated GitHub repository of Market Structure + Supply/Demand
55 stars

This Pine Script indicator overlays institutional liquidity levels on the price chart. It identifies order block levels using pivot highs and lows, then draws mean reversion lines from the 20 and 50 period simple moving averages, a volatility range midpoint pr

Indicator v6 Support & resistanceSMC / ICT / price action Repaints
Updated 7 months ago · Apache-2.0 GitHub repository of AAPL Institutional Liquidity Grid

This indicator combines six trading tools into a single chart overlay to optimize indicator limits. It calculates Bollinger Bands, projects weekend price boundaries, plots market structure elements like order blocks, breaker blocks, and MSB lines, marks New Yo

Indicator v6 Support & resistanceSMC / ICT / price action Repaints

More SMC / ICT 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