1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
79 lines of Pine Script v5 from scripts/pattern_levels.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
pattern_levels.pine
//@version=5
// Pattern Trade Levels — companion to scripts/pattern_scan.py (issue #348).
// Type in the boundary and pattern low from any chart pattern; draws
// confirm (+3%), measured-move target, both stop conventions, and an R:R table.
// Levels are drawn as hand-built long-dash segments (Pine's style_dashed is a
// fixed micro-dash; the drawing-tool look needs manual segments).
indicator("Pattern Trade Levels", overlay = true, max_lines_count = 500, max_labels_count = 20)
B = input.float(0.0, "Boundary / breakout level (B)", step = 0.01)
L = input.float(0.0, "Pattern low (L)", step = 0.01)
S = input.float(0.0, "Structural stop (last higher low, 0=off)", step = 0.01)
confPct = input.float(3.0, "Confirm / negation buffer %", step = 0.1, minval = 0)
useLog = input.bool(true, "Log measured move (BxB/L) — off = B+(B-L)")
entryOpt = input.string("Confirm", "Entry for R:R", options = ["Confirm", "Boundary", "Current price"])
dashOn = input.int(6, "Dash length (bars)", minval = 1, group = "Style")
dashOff = input.int(5, "Dash gap (bars)", minval = 1, group = "Style")
spanBack = input.int(260, "Extend left (bars)", minval = 20, maxval = 5000, group = "Style")
spanFwd = input.int(30, "Extend right (bars)", minval = 0, maxval = 400, group = "Style")
confirm = B * (1 + confPct / 100) // daily close above = validated breakout
negStop = B * (1 - confPct / 100) // close back below after breakout = failed
target = useLog ? B * B / L : B + (B - L)
entry = entryOpt == "Confirm" ? confirm : entryOpt == "Boundary" ? B : close
stopUsed = S > 0 ? S : negStop
rr = entry - stopUsed > 0 ? (target - entry) / (entry - stopUsed) : na
var lvlLines = array.new<line>()
var lvlLabels = array.new<label>()
f_clear() =>
while array.size(lvlLines) > 0
line.delete(array.pop(lvlLines))
while array.size(lvlLabels) > 0
label.delete(array.pop(lvlLabels))
f_lvl(float y, color col, string txt) =>
i = math.max(0, bar_index - spanBack)
rightEdge = bar_index + spanFwd
// At most 95 segments per level keeps all five levels below 500 IDs.
spacing = math.max(dashOn + dashOff, int(math.ceil((rightEdge - i) / 95.0)))
while i < rightEdge
array.push(lvlLines, line.new(i, y, math.min(i + dashOn, rightEdge), y, color = col, width = 1,
style = line.style_solid))
i += spacing
array.push(lvlLabels, label.new(bar_index - 30, y,
txt + " " + str.tostring(y, format.mintick),
color = color.new(color.black, 100), textcolor = col,
style = label.style_none, size = size.normal))
if barstate.islast
f_clear()
if barstate.islast and B > 0 and L > 0 and L < B
f_lvl(B, color.fuchsia, "boundary")
f_lvl(confirm, color.aqua, "confirm +" + str.tostring(confPct, "#.#") + "%")
f_lvl(target, color.lime, "target")
f_lvl(negStop, color.orange, "negation stop")
if S > 0
f_lvl(S, color.red, "structural stop")
var table t = table.new(position.top_right, 2, 5, bgcolor = color.new(color.black, 20))
table.cell(t, 0, 0, "Entry (" + entryOpt + ")", text_color = color.gray, text_size = size.small)
table.cell(t, 1, 0, str.tostring(entry, format.mintick), text_color = color.white, text_size = size.small)
table.cell(t, 0, 1, "Target", text_color = color.gray, text_size = size.small)
table.cell(t, 1, 1, str.tostring(target, format.mintick) + " (+" + str.tostring((target / entry - 1) * 100, "#.#") + "%)",
text_color = color.lime, text_size = size.small)
table.cell(t, 0, 2, "Stop", text_color = color.gray, text_size = size.small)
table.cell(t, 1, 2, str.tostring(stopUsed, format.mintick) + " (-" + str.tostring((1 - stopUsed / entry) * 100, "#.#") + "%)",
text_color = color.orange, text_size = size.small)
table.cell(t, 0, 3, "R : R", text_color = color.gray, text_size = size.small)
table.cell(t, 1, 3, na(rr) ? "n/a" : str.tostring(rr, "#.##") + "R",
text_color = rr >= 2 ? color.lime : color.red, text_size = size.small)
table.cell(t, 0, 4, "Dist to confirm", text_color = color.gray, text_size = size.small)
table.cell(t, 1, 4, str.tostring((confirm / close - 1) * 100, "#.##") + "%",
text_color = color.white, text_size = size.small)
alertcondition(B > 0 and ta.crossover(close, confirm), "Confirm breakout",
"Price crossed above the confirm level — breakout validated")
alertcondition(B > 0 and ta.crossover(close, B), "Boundary touch",
"Price crossed above the pattern boundary")
Overview
Pattern Trade Levels draws the breakout boundary, a confirmation level and a negation stop from a percentage buffer, a measured-move target using either a log formula or an arithmetic extension, and an optional structural stop. A corner table shows the selected entry, target, stop, and reward-to-risk ratio. Lines appear only when the boundary is above the pattern low, and the script places no orders.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Boundary / breakout level (B)
float
0.0
B
Pattern low (L)
float
0.0
L
Structural stop (last higher low, 0=off)
float
0.0
S
Confirm / negation buffer %
float
3.0
confPct
Log measured move (BxB/L) — off = B+(B-L)
bool
true
useLog
Entry for R:R
string
Confirm
entryOpt
Dash length (bars)
int
6
dashOn
Dash gap (bars)
int
5
dashOff
Extend left (bars)
int
260
spanBack
Extend right (bars)
int
30
spanFwd
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.
Sideway Zones Live is an overlay indicator that estimates inner and outer sideways bands from recent highs and lows with a rational quadratic kernel. It tracks swing pivots over a loopback period and counts bars that remain between the outer high and low. Afte
This indicator identifies High Of Low Price (HOLP) and Low Of High Price (LOHP) candlestick setups based on price extremes over a specified lookback period. A HOLP signal triggers when the current bar closes above the high of a recent session low, whereas a LO
This indicator plots dynamic support and resistance levels on the price chart. It detects pivot highs and lows using the pivot length and tracks touches to build strength-based levels. Support and resistance zones appear as colored boxes while lines mark key l
This indicator calculates and plots Donchian Channels directly on the price chart. It determines the highest high and lowest low over a user-selected lookback period using an optimized monotonic deque algorithm, as well as a middle basis line computed as their
This indicator tracks bar lows during consecutive rising highs using Pine Script arrays. When at least four lows accumulate or the price breaches the minimum low in the stack, the script sorts the recorded lows in ascending order and flushes them. It plots up
This indicator tracks smart money market structure directly on the price chart. It calculates dual-period swing highs and swing lows to detect Changes of Character (CHoCH), Breaks of Structure (BOS), inducements, and liquidity sweeps. When structural levels ar