If you already read market structure by hand, learning SMC Pine Script is the next step: it turns the same rules you apply with your eyes into rules a TradingView indicator can apply on every bar. This guide shows how the core Smart Money Concepts translate into Pine Script v6 — detecting swings, comparing them to label trend structure, marking a break of structure (BOS), and drawing labels and lines on the chart.
It is written for traders who want to understand the mechanics, not for traders looking for a finished tool. The code below is deliberately small.
Important: the snippets in this article are simplified teaching examples only. They are NOT a complete indicator, and they are NOT JUKA's code. A production indicator has to handle state across many bars, clear old levels, manage labels and lines so the chart stays readable, and deal with edge cases these short examples skip. Use the snippets to learn how each piece works, then decide whether you want to build further or use a finished tool.
Smart Money Concepts Pine Script is, at its core, Market structure Pine Script: a set of comparisons between swing highs and swing lows.
In plain language, the method asks three questions in order:
Everything else — trend labels, BOS and change of character (CHoCH), premium and discount zones, inducement, and order blocks — is built on top of those three answers. That is why swing detection matters so much: if the swings are wrong, every label built on them is wrong too.
A common beginner mistake is to treat every local high as a swing. In code, a swing needs a definition: how many bars to the left and right must be lower (for a high) or higher (for a low) before the bar counts. Change that definition and you change the whole structure map, which is why two indicators can plot the same labels and still disagree.
TradingView made v6 the current version of Pine Script, and every snippet in this guide uses //@version=6. Three changes matter for structure code:
na. A bool is always true or false, so test the price series with na() — as the examples do with not na(swingHigh) — rather than testing a boolean for na.and / or are evaluated lazily. In not na(lastHigh) and ta.crossover(close, lastHigh) the right side is skipped when the left side is false. Functions that must run on every bar, such as ta.crossover, are safer assigned to a variable first if you rely on their history.x != 0 instead of using a number as a condition.If you have an older v5 script, TradingView's editor offers an automatic converter; check its output against these three points.
Pine Script v6 already has built-in pivot functions, which makes Smart Money structure Pine Script much easier to start with than writing pivot logic from scratch.
ta.pivothigh returns the price of a pivot high once it is confirmed by the bars to its right. ta.pivotlow does the same for a pivot low. Both return na on bars where no new pivot is confirmed.
//@version=6
indicator("SMC Teaching — Swings", overlay = true)
leftBars = input.int(5, "Left bars")
rightBars = input.int(5, "Right bars")
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
plotshape(not na(swingHigh), title = "Swing high", style = shape.triangledown, location = location.abovebar, color = color.red)
plotshape(not na(swingLow), title = "Swing low", style = shape.triangleup, location = location.belowbar, color = color.teal)
Two practical points follow from this code:
rightBars = 5, a high is only recognised five bars after it forms. That lag is not a bug; it is what "confirmed" means. Live, unconfirmed highs will move. Confirmed structure should not.If you only want to act on closed bars, guard your logic with barstate.isconfirmed. That keeps an indicator from reacting to a bar that is still forming and may yet change:
if barstate.isconfirmed and not na(swingHigh)
// Only now treat the swing high as a closed-bar event.
label.new(bar_index - rightBars, swingHigh, "SH")
Once you have swings, labelling them is a comparison. Keep the previous swing high and low in variables, then compare each new swing with the previous one of the same kind.
In code, that means storing state with var so the value survives from bar to bar:
//@version=6
indicator("SMC Teaching — Swing labels", overlay = true)
leftBars = input.int(5, "Left bars")
rightBars = input.int(5, "Right bars")
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
var float lastHigh = na
var float lastLow = na
if not na(swingHigh)
swingLabel = na(lastHigh) or swingHigh > lastHigh ? "HH" : "LH"
label.new(bar_index - rightBars, swingHigh, swingLabel, style = label.style_label_down, color = color.new(color.gray, 0), textcolor = color.white)
lastHigh := swingHigh
if not na(swingLow)
swingLabel = na(lastLow) or swingLow > lastLow ? "HL" : "LL"
label.new(bar_index - rightBars, swingLow, swingLabel, style = label.style_label_up, color = color.new(color.gray, 0), textcolor = color.white)
lastLow := swingLow
Note the offset bar_index - rightBars: the pivot bar itself is rightBars bars back, not the current bar. Placing the label on the current bar is a common teaching-example error, and it makes the chart look shifted.
This is still simplified. A full structure map also tracks the sequence of highs and lows together — for example, an HH followed by an HL describes an uptrend leg, while an LH followed by an LL describes a downtrend leg — and it removes or updates labels as structure evolves. The snippet above shows only the comparison at the heart of that logic.
A break of structure happens when price closes through the last relevant swing level. In an uptrend, the level to watch is the last swing high; a close above it confirms continuation. In a downtrend, the level is the last swing low; a close below it confirms continuation.
Pine Script v6 gives you ta.crossover and ta.crossunder for exactly this test: they are true on the bar where one series crosses above or below another.
//@version=6
indicator("SMC Teaching — BOS", overlay = true)
leftBars = input.int(5, "Left bars")
rightBars = input.int(5, "Right bars")
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
var float lastHigh = na
var float lastLow = na
if not na(swingHigh)
lastHigh := swingHigh
if not na(swingLow)
lastLow := swingLow
bosUp = not na(lastHigh) and ta.crossover(close, lastHigh)
bosDown = not na(lastLow) and ta.crossunder(close, lastLow)
plotshape(bosUp, title = "BOS up", style = shape.labelup, location = location.belowbar, color = color.teal, text = "BOS")
plotshape(bosDown, title = "BOS down", style = shape.labeldown, location = location.abovebar, color = color.red, text = "BOS")
A change of character (CHoCH) uses the same crossing test, but against the swing level in the opposite direction to the prevailing trend — a close through a swing low during an uptrend, or through a swing high during a downtrend. The code is nearly identical; the difference is which level you test and how you interpret the result. That is why a clear trend state matters: without it, the same cross can be read as either continuation or reversal.
Two related functions are useful when you move beyond single levels. ta.highest and ta.lowest return the highest high or lowest low over a lookback window, which is handy for defining a dealing range and its midpoint:
rangeHigh = ta.highest(high, 50)
rangeLow = ta.lowest(low, 50)
equilibrium = (rangeHigh + rangeLow) / 2.0
Price above equilibrium sits in the premium part of that range; price below it sits in discount. Again, this is a teaching simplification — a production method defines which range counts, not just the last 50 bars — but it shows how premium and discount follow directly from swing and range logic.
Labels mark events. Lines mark levels. A BOS level is more useful drawn across the chart than marked at a single bar, because you want to see price approach it before the break happens.
//@version=6
indicator("SMC Teaching — BOS level", overlay = true)
leftBars = input.int(5, "Left bars")
rightBars = input.int(5, "Right bars")
swingHigh = ta.pivothigh(high, leftBars, rightBars)
var line bosLine = na
if not na(swingHigh)
if not na(bosLine)
line.delete(bosLine)
bosLine := line.new(bar_index - rightBars, swingHigh, bar_index, swingHigh, color = color.new(color.teal, 0), style = line.style_dashed, extend = extend.right)
A few habits keep this kind of drawing readable:
That confirmed-versus-projected distinction is the honest way to talk about repainting. Confirmed structure — swings and breaks already confirmed by closed price action — should never be redrawn or shifted. Live projected levels update until confirmation. Any tool that blurs those two categories will mislead you when you look back over past charts, even if its chart looks clean in real time.
Deliberately, the examples above do not cover inducement (IDM), liquidity sweeps, or order blocks in full. Each adds a layer of state:
high, low, and close together, not a single cross.None of these is hard in isolation. The difficulty is keeping them consistent: the swing that defines the BOS level must be the same swing that defines the pullback, the inducement, and the block. If each element is computed by a different rule, the chart looks complete while the reasoning behind it is not. That consistency is what separates a method from a collection of labels.
There are two honest paths from here.
Building it yourself is the best way to learn. Start with swings, add HH/HL/LH/LL labels, then BOS, then one more layer at a time, testing each addition on charts you already know by hand. Expect the work to be mostly state management — tracking levels, clearing old drawings, and handling sideways markets — rather than finding new functions.
Using a finished indicator is the best way to save daily labour once you already understand the method. That is the trade the Trading Hub 3.0 indicator is built for: JUKA is a TradingView indicator built on the Trading Hub 3.0 method. It automatically maps market structure on any symbol and any timeframe: swing and pullback points with the protected swing circled, BOS, CHoCH, inducement (IDM), the premium/discount equilibrium (0.5) line, liquidity sweeps, and order blocks. Confirmed structure is never redrawn; live projected BOS/CHoCH/IDM levels update until confirmed.
Pricing is straightforward: lifetime invite-only access is $60; full Pine Script source code is $99 one-time; and you can try it free for 3 days through Telegram @hotayxanhvn. If you only want to use the indicator on TradingView, the invite is enough. If you want to adapt the logic to your own rules, the full source code is the route — for personal use, with redistribution, resale, or republishing prohibited under the license.
Whichever path you take, the test is the same: run it on your own symbols and timeframes, in current market conditions, and check whether confirmed history stays put while projected levels update cleanly. A structure tool earns trust bar by bar, not by its feature list.
JUKA on NEAR 1H — every label drawn by the indicator.
Do I need to know Pine Script v6 to use an SMC indicator?
No. You need Pine Script only if you want to build or modify one. To use a finished indicator, you need to understand the concepts — swings, BOS, CHoCH, and inducement — well enough to read what it draws.
Why do my pivot labels appear a few bars late?
Because ta.pivothigh and ta.pivotlow confirm a pivot only after the bars to its right have closed. That delay is the price of confirmation. An indicator that labelled a high on the bar it formed would be labelling an unconfirmed extreme.
Is a break of structure a buy or sell signal?
No. BOS maps structure; it does not tell you when to click buy or sell. It tells you the trend leg continued, which is one piece of context for a decision you still have to make yourself.
Should I start with the invite or the source code?
If you want to use the finished Trading Hub 3.0 method as drawn, start with the invite and the free 3-day trial. If you want to study or adapt the Pine Script v6 implementation for your own use, get the source code.
Not financial advice.