We use cookies to understand how the site is used and improve it. We only load analytics after you accept. Privacy Policy
A confirmed 55-bar channel-breakout strategy with an optional EMA filter, ATR-based stops, partial exits, and a 20-bar exit channel.
Published by AlgoNexta, who builds and documents these tools so you can inspect the logic before using it. About AlgoNexta · Trading Scripts · AlgoNexta Research
Breakout Ladder is a TradingView strategy, not just a plotted signal. It compares each confirmed close with channels calculated from *earlier* bars, optionally filters entries with a base EMA, and submits market entries and stop-based exit orders. Its default plan closes part of a position at fixed targets and leaves the final part to the stop or exit channel.
01 · When it signals
After the required history is available, a confirmed close must newly exceed the prior 55-bar high or fall below the prior 55-bar low. The default EMA(200) filter requires the close to be above it for a long or below it for a short; without a new crossing, there is no entry signal.
02 · How it enters and sets risk
On a confirmed, permitted signal, the strategy submits one market entry, normally filled at the next open. It plans an initial stop 2.0 × ATR(20) from the signal close, sizes for 1.0% equity risk subject to a 0.9× equity position cap, and derives target levels from that planned distance; fills can differ from the plan.
03 · How the remainder exits
With three targets and the default last-exit setting, fixed orders take 30% at 1.5R and 30% at 3.0R, while the remainder has no fixed 5.0R order. After target 1 is marked reached, the stop can move to the average fill price; the enabled exit-channel rule also closes a remaining long below the prior 20-bar low or a short above the prior 20-bar high on a confirmed close.
2 prompts, typed into NexaScript Studio on XAUUSD D1. Each step is the whole prompt after the change, so the last one rebuilds the script on its own.
The one-minute version
The same build in under a minute, made for phones.
Prompt 1
Buy gold when the daily close breaks above the highest high of the last 55 days. Sell when it breaks below the lowest low of the last 55 days.
5-year backtest (Dec 2021 to Nov 2026, 1% risk, 2 ATR stop): +23.1%, 37 trades, 54.1% winners, profit factor 2.2, max drawdown 3.98%. It trades against the long-term trend too.
Prompt 2 · final
This script's logic could not be confidently reconstructed into an automated reference backtest, so no performance figures are shown rather than estimated ones.
Verify it in TradingView's Strategy Tester (or the equivalent tool for tradingview) before relying on it.
Vision Grade requires a reference backtest with enough reconstructed entries to measure — not available for this script yet.
Published by AlgoNexta, an evidence-first platform for building, reviewing, and documenting algorithmic trading tools. This page explains the script's actual logic and intended use; it does not promise profitability or replace verification in TradingView.
Breakout Ladder is a TradingView strategy, not just a plotted signal. It compares each confirmed close with channels calculated from *earlier* bars, optionally filters entries with a base EMA, and submits market entries and stop-based exit orders. Its default plan closes part of a position at fixed targets and leaves the final part to the stop or exit channel.
[1].close > EMA, and shorts require close < EMA. Direction defaults to Both.Initial stop (ATR) defaults to 2.0 × ATR(20) from the *signal close*. That distance defines 1R for sizing and target placement, even if the eventual fill differs. Risk per trade (% of equity) defaults to 1.0%, subject to Largest position (multiple of equity) at 0.9; actual loss can differ because of fills, gaps, costs, or the position cap. The strategy also configures 0.01% commission and 2 ticks of slippage in its backtest settings.
Number of targets defaults to 3. Target 1 is 1.5R and closes 30% of initial size; target 2 is 3.0R and closes 30%. Target 3 is configured at 5.0R, but the default The last part exits by: Only the stop or the strategy's own exit means the remaining portion has no fixed target order. Changing that setting to Its fixed target enables the last target; A trailing stop instead uses the exit-channel price after the configured Trailing starts after target threshold, default 1. Trailing distance (ATR) defaults to 3.0, but is not used in the implemented trailing-price calculation.
Move the stop defaults to To entry after target 1. The code marks a target as reached when that bar’s high or low touches its level, then updates the stop using the strategy’s average fill price; that touch check is not proof that a particular partial order filled. A stop change decided during a bar applies through subsequent exit-order processing. With Close on the exit channel enabled, a remaining long is closed after a confirmed close below the preceding 20-bar low; a short is closed above the preceding 20-bar high. This close order, like an entry, is distinct from an intrabar stop fill.
Max new positions per day (0 = no limit) and No new entries after a daily loss of % (0 = off) both default to 0, so neither blocks entries initially. If enabled, they restrict *new* positions; the loss guard measures the change in strategy equity since the day’s first bar and does not close an open trade.
The price panel shows a teal breakout high, red breakout low, subdued base EMA, and an exit-channel line while a trade is tracked. With Show stop and targets on, the stop is red and applicable, unreached target lines are teal. These levels describe the strategy’s planned orders, not guaranteed executions. Show status table is on by default at Top right; it reports trade state, target progress, stop, channel and EMA status, position count, and historical Strategy Tester-derived results. Entry alerts include the approximate signal-close entry, stop, and first target; separate alerts fire when the code’s high/low checks mark targets 1–3 as reached. Create a TradingView alert for the strategy’s alert() calls to receive them.
No particular market or chart timeframe is specified. Choose a chart with sufficient history for the 55-bar and 20-bar channels, EMA(200), and ATR(20); unavailable warm-up values cannot establish a breakout. The channel calculations use prior bars and entries require confirmed closes, so the entry rule does not rely on an unfinished bar’s final close. Intrabar stop and target fills remain subject to TradingView’s historical bar-fill assumptions; target-touch alerts and plotted levels should not be read as independent fill confirmations. The script does not test volume or detect discretionary chart patterns. Historical Strategy Tester output, native compilation, paper trading, and live execution are different evidence levels; none alone verifies future results.
breakout-ladder-channel-breakout-strategy-algonexta.pine · 277 lines · 20.4 KB
Not yet verified on the native platform — test it before relying on it.
The original uploaded source.
// ============================================================================
// © algonexta
// This script is for education and research; it does not guarantee results.
// Verify this source in TradingView before use.
// ============================================================================
// Breakout Ladder. A channel breakout in the spirit of the classic trend-following rules: it enters on a
// close beyond the 55-bar range, closes in steps, and lets the last part ride until the 20-bar exit channel.
// Backtest results describe the past only and do not predict future results. Not financial advice.
//@version=6
strategy("Breakout Ladder: Channel Breakout Strategy [AlgoNexta]", shorttitle = "Breakout Ladder", overlay = true, initial_capital = 10000, currency = currency.NONE, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, commission_type = strategy.commission.percent, commission_value = 0.01, slippage = 2, pyramiding = 0, max_boxes_count = 300, max_lines_count = 300, max_labels_count = 300)
string NAME = "Breakout Ladder"
//──────────────────────────────────────────────────────────────────────────────
// Strategy inputs
//──────────────────────────────────────────────────────────────────────────────
string G_CH = "Channel"
string G_ENT = "Entry and exit"
int entryLen = input.int(55, "Breakout channel (bars)", minval = 5, maxval = 400, group = G_CH, tooltip = "A long starts when a bar closes above the highest high of this many earlier bars. Mirrored for shorts.", display = display.none)
int exitLen = input.int(20, "Exit channel (bars)", minval = 2, maxval = 200, group = G_CH, tooltip = "The remaining position closes when a bar closes below the lowest low of this many earlier bars (above the highest high for a short).", display = display.none)
bool useBase = input.bool(true, "Trade only on the right side of the base EMA", group = G_CH, display = display.none)
int baseLen = input.int(200, "Base EMA", minval = 20, group = G_CH, display = display.none)
float stopAtr = input.float(2.0, "Initial stop (ATR)", minval = 0.5, step = 0.25, group = G_ENT, tooltip = "Distance from the signal close to the initial stop, in ATR(20). This distance is 1R.", display = display.none)
bool useExit = input.bool(true, "Close on the exit channel", group = G_ENT, display = display.none)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LADDER RISK ENGINE, part 1 of 3: inputs. This block is the same in all AlgoNexta Ladder
// strategies; only the default values differ.
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string G_RISK = "Risk"
string G_TP = "Targets: the position is closed in steps"
string G_STOP = "Stop management"
string G_DAY = "Daily guard"
string G_VIS = "Display"
string SM_OFF = "Never"
string SM_BE = "To entry after target 1"
string SM_STEP = "To entry after target 1, then one target behind"
string LE_FIX = "Its fixed target"
string LE_TRL = "A trailing stop"
string LE_NONE = "Only the stop or the strategy's own exit"
float riskPct = input.float(1.0, "Risk per trade (% of equity)", minval = 0.1, maxval = 5.0, step = 0.1, group = G_RISK, tooltip = "The position size is set so that a full stop-out from the signal price loses this share of equity. 1R is the distance from the signal bar's close to the initial stop.", display = display.none)
float maxLev = input.float(0.9, "Largest position (multiple of equity)", minval = 0.1, maxval = 20.0, step = 0.1, group = G_RISK, tooltip = "Caps the position when the stop is very close. With the default 100% margin, keep this below 1.", display = display.none)
string tradeDir = input.string("Both", "Direction", options = ["Both", "Long only", "Short only"], group = G_RISK, display = display.none)
int nT = input.int(3, "Number of targets", minval = 1, maxval = 4, group = G_TP, tooltip = "1 to 4 steps. Each step closes part of the position at its target. The last active step always closes whatever is left.", display = display.none)
float t1R = input.float(1.5, "Target 1 (R)", minval = 0.2, step = 0.25, group = G_TP, display = display.none)
float p1 = input.float(30, "Target 1 closes (% of the position)", minval = 1, maxval = 100, group = G_TP, display = display.none)
float t2R = input.float(3.0, "Target 2 (R)", minval = 0.2, step = 0.25, group = G_TP, display = display.none)
float p2 = input.float(30, "Target 2 closes (% of the position)", minval = 1, maxval = 100, group = G_TP, display = display.none)
float t3R = input.float(5.0, "Target 3 (R)", minval = 0.2, step = 0.25, group = G_TP, display = display.none)
float p3 = input.float(20, "Target 3 closes (% of the position)", minval = 1, maxval = 100, group = G_TP, display = display.none)
float t4R = input.float(6.0, "Target 4 (R)", minval = 0.2, step = 0.25, group = G_TP, tooltip = "Percentages are shares of the initial position. Keep their sum below 100 so that the last step has something left to close.", display = display.none)
string lastExit = input.string(LE_NONE, "The last part exits by", options = [LE_FIX, LE_TRL, LE_NONE], group = G_TP, tooltip = "Its fixed target: the last step closes at its own target. A trailing stop: the last step has no target and leaves when the trailing stop is hit. Only the stop or the strategy's own exit: no target and no trailing; the last part rides until the (moved) stop, the session end or a trend flip, depending on the strategy.", display = display.none)
int trailFrom = input.int(1, "Trailing starts after target", minval = 0, maxval = 3, group = G_TP, tooltip = "0: the stop trails from the entry. 1: after target 1 is reached, and so on. Used only when the last part exits by a trailing stop.", display = display.none)
float trailMult = input.float(3.0, "Trailing distance (ATR)", minval = 0.5, step = 0.25, group = G_TP, display = display.none)
string stopMove = input.string(SM_BE, "Move the stop", options = [SM_OFF, SM_BE, SM_STEP], group = G_STOP, tooltip = "The stop only ever moves in the trade's favour. A move decided on one bar takes effect from the next bar.", display = display.none)
int maxDayTrades = input.int(0, "Max new positions per day (0 = no limit)", minval = 0, group = G_DAY, display = display.none)
float maxDayLoss = input.float(0.0, "No new entries after a daily loss of % (0 = off)", minval = 0.0, step = 0.5, group = G_DAY, tooltip = "Measured on equity since the first bar of the day. Open trades are not closed by this rule.", display = display.none)
bool showLevels = input.bool(true, "Show stop and targets", group = G_VIS, display = display.none)
bool showTable = input.bool(true, "Show status table", group = G_VIS, display = display.none)
string tblPos = input.string("Top right", "Table position", options = ["Top right", "Top left", "Bottom right", "Bottom left"], group = G_VIS, display = display.none)
color upCol = input.color(#22ab94, "Long / target colour", group = G_VIS, display = display.none)
color dnCol = input.color(#f23645, "Short / stop colour", group = G_VIS, display = display.none)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LADDER RISK ENGINE, part 2 of 3: state and order functions (identical in all five strategies).
// One position at a time. Entry is a market order sent at the close of the signal bar; it fills
// at the next bar's open. Stop and targets are fixed prices measured from the signal bar's close.
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
type Trade
int dir = 0 // 1 long, -1 short, 0 no trade
float entry = na // signal bar close (planned entry)
float stop = na // live stop price
float risk = na // 1R as a price distance
float qty = na // initial position size
float t1 = na
float t2 = na
float t3 = na
float t4 = na
bool h1 = false // price has reached target 1
bool h2 = false
bool h3 = false
int bar = na // signal bar
int count = 0 // positions taken so far
var Trade tr = Trade.new()
// Daily guard
bool newDay = timeframe.change("D")
var float dayEq = na
var int dayTrades = 0
if newDay or na(dayEq)
dayEq := strategy.equity
dayTrades := 0
bool dayOk = (maxDayTrades == 0 or dayTrades < maxDayTrades) and (maxDayLoss == 0 or (strategy.equity - dayEq) / dayEq * 100.0 > -maxDayLoss)
f_pos(string s) =>
s == "Top left" ? position.top_left : s == "Bottom right" ? position.bottom_right : s == "Bottom left" ? position.bottom_left : position.top_right
// The stop that protects more: the higher one for a long, the lower one for a short.
f_better(int dir, float a, float b) =>
dir == 1 ? math.max(a, b) : math.min(a, b)
// Units that risk riskPct of equity over the stop distance, capped by the position limit.
f_qty(float dist) =>
float riskCash = strategy.equity * riskPct / 100.0
float byRisk = riskCash / (dist * syminfo.pointvalue)
float byCap = strategy.equity * maxLev / (close * syminfo.pointvalue)
math.max(0.0, math.min(byRisk, byCap))
// Call once per bar BEFORE the entry logic: forgets a trade that has been fully closed.
f_sync(Trade t) =>
if t.dir != 0 and strategy.position_size == 0 and bar_index > t.bar
t.dir := 0
t.dir
// Opens a trade if none is open. Returns true when the entry order was sent.
f_open(Trade t, int dir, float stop) =>
bool opened = false
float dist = math.abs(close - stop)
bool side = dir == 1 ? stop < close : stop > close
if strategy.position_size == 0 and t.dir == 0 and side and dist > syminfo.mintick
float q = f_qty(dist)
if q > 0
t.dir := dir
t.entry := close
t.stop := stop
t.risk := dist
t.qty := q
t.t1 := close + dir * t1R * dist
t.t2 := close + dir * t2R * dist
t.t3 := close + dir * t3R * dist
t.t4 := close + dir * t4R * dist
t.h1 := false
t.h2 := false
t.h3 := false
t.bar := bar_index
t.count := t.count + 1
strategy.entry(dir == 1 ? "Long" : "Short", dir == 1 ? strategy.long : strategy.short, qty = q)
alert(NAME + ": " + (dir == 1 ? "LONG " : "SHORT ") + syminfo.ticker + " at about " + str.tostring(close, format.mintick) + ", stop " + str.tostring(stop, format.mintick) + ", target 1 " + str.tostring(t.t1, format.mintick), alert.freq_once_per_bar_close)
opened := true
opened
// Call once per bar AFTER the entry logic: marks reached targets, moves the stop, and keeps one
// exit order per remaining step. trailPx is the trailing price that the strategy logic proposes, or na for none.
f_manage(Trade t, float trailPx) =>
if t.dir != 0
int d = t.dir
string id = d == 1 ? "Long" : "Short"
string px = d == 1 ? "L" : "S"
if strategy.position_size != 0
if not t.h1 and (d == 1 ? high >= t.t1 : low <= t.t1)
t.h1 := true
alert(NAME + ": target 1 reached on " + syminfo.ticker, alert.freq_once_per_bar_close)
if nT >= 2 and not t.h2 and (d == 1 ? high >= t.t2 : low <= t.t2)
t.h2 := true
alert(NAME + ": target 2 reached on " + syminfo.ticker, alert.freq_once_per_bar_close)
if nT >= 3 and not t.h3 and (d == 1 ? high >= t.t3 : low <= t.t3)
t.h3 := true
alert(NAME + ": target 3 reached on " + syminfo.ticker, alert.freq_once_per_bar_close)
float ns = t.stop
if stopMove != SM_OFF and t.h1
ns := f_better(d, ns, strategy.position_avg_price)
if stopMove == SM_STEP
if t.h2
ns := f_better(d, ns, t.t1)
if t.h3
ns := f_better(d, ns, t.t2)
int hits = (t.h1 ? 1 : 0) + (t.h2 ? 1 : 0) + (t.h3 ? 1 : 0)
if lastExit == LE_TRL and hits >= trailFrom and not na(trailPx) and (d == 1 ? trailPx < close : trailPx > close)
ns := f_better(d, ns, trailPx)
t.stop := ns
// Steps before the last one: a fixed share of the initial position each.
if nT >= 2 and not t.h1
strategy.exit(px + "1", id, qty = t.qty * p1 / 100.0, limit = t.t1, stop = t.stop, comment_profit = "T1", comment_loss = "Stop")
if nT >= 3 and not t.h2
strategy.exit(px + "2", id, qty = t.qty * p2 / 100.0, limit = t.t2, stop = t.stop, comment_profit = "T2", comment_loss = "Stop")
if nT >= 4 and not t.h3
strategy.exit(px + "3", id, qty = t.qty * p3 / 100.0, limit = t.t3, stop = t.stop, comment_profit = "T3", comment_loss = "Stop")
// Last step: whatever is left, at its target or with no target when it trails.
float lastT = nT == 1 ? t.t1 : nT == 2 ? t.t2 : nT == 3 ? t.t3 : t.t4
float lim = lastExit == LE_FIX ? lastT : na
strategy.exit(px + "F", id, limit = lim, stop = t.stop, comment_profit = "Last target", comment_loss = "Stop")
t.dir
//──────────────────────────────────────────────────────────────────────────────
// Channels
//──────────────────────────────────────────────────────────────────────────────
float atr = ta.atr(20)
float emaB = ta.ema(close, baseLen)
float upE = ta.highest(high, entryLen)[1]
float dnE = ta.lowest(low, entryLen)[1]
float upX = ta.highest(high, exitLen)[1]
float dnX = ta.lowest(low, exitLen)[1]
bool longSig = close > upE and close[1] <= upE[1] and (not useBase or close > emaB)
bool shortSig = close < dnE and close[1] >= dnE[1] and (not useBase or close < emaB)
float longStop = close - stopAtr * atr
float shortStop = close + stopAtr * atr
//──────────────────────────────────────────────────────────────────────────────
// Orders: confirmed bars only
//──────────────────────────────────────────────────────────────────────────────
f_sync(tr)
bool opened = false
if barstate.isconfirmed and dayOk
if longSig and tradeDir != "Short only"
opened := f_open(tr, 1, longStop)
else if shortSig and tradeDir != "Long only"
opened := f_open(tr, -1, shortStop)
if opened
dayTrades += 1
if useExit and barstate.isconfirmed and strategy.position_size != 0 and bar_index > tr.bar
if tr.dir == 1 and close < dnX
strategy.close("Long", comment = "Exit channel")
if tr.dir == -1 and close > upX
strategy.close("Short", comment = "Exit channel")
// Trailing price, used only when the last part exits by a trailing stop: the exit channel.
f_manage(tr, tr.dir == 1 ? dnX : upX)
plot(upE, "Breakout high", color = color.new(upCol, 40), display = display.all - display.status_line)
plot(dnE, "Breakout low", color = color.new(dnCol, 40), display = display.all - display.status_line)
plot(tr.dir == 1 ? dnX : tr.dir == -1 ? upX : na, "Exit channel", color = color.new(chart.fg_color, 50), style = plot.style_linebr, display = display.all - display.status_line)
plot(useBase ? emaB : na, "Base EMA", color = color.new(chart.fg_color, 65), display = display.all - display.status_line)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LADDER RISK ENGINE, part 3 of 3: stop and target lines, status table (identical in all five).
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_lvl(int i, float price, bool reached) =>
showLevels and tr.dir != 0 and nT >= i and not reached and not (i == nT and lastExit != LE_FIX) ? price : na
plot(showLevels and tr.dir != 0 ? tr.stop : na, "Stop", color = dnCol, style = plot.style_linebr, linewidth = 2, display = display.all - display.status_line)
plot(f_lvl(1, tr.t1, tr.h1), "Target 1", color = upCol, style = plot.style_linebr, display = display.all - display.status_line)
plot(f_lvl(2, tr.t2, tr.h2), "Target 2", color = upCol, style = plot.style_linebr, display = display.all - display.status_line)
plot(f_lvl(3, tr.t3, tr.h3), "Target 3", color = upCol, style = plot.style_linebr, display = display.all - display.status_line)
plot(f_lvl(4, tr.t4, false), "Target 4", color = upCol, style = plot.style_linebr, display = display.all - display.status_line)
var table tb = table.new(f_pos(tblPos), 2, 8, bgcolor = color.new(chart.bg_color, 10), border_color = color.new(chart.fg_color, 85), border_width = 1, frame_color = color.new(chart.fg_color, 70), frame_width = 1)
f_cell(int col, int row, string txt, color c) =>
table.cell(tb, col, row, txt, text_color = c, text_size = size.small, text_halign = text.align_left)
// Two rows (k1/v1 and k2/v2) belong to the strategy; the rest is the same everywhere.
f_dash(string k1, string v1, string k2, string v2) =>
if showTable and (barstate.islastconfirmedhistory or barstate.isrealtime)
color fg = chart.fg_color
int hits = (tr.h1 ? 1 : 0) + (tr.h2 ? 1 : 0) + (tr.h3 ? 1 : 0)
string stateTxt = tr.dir == 0 ? "No trade" : (tr.dir == 1 ? "Long" : "Short") + ", now " + str.tostring((close - tr.entry) * tr.dir / tr.risk, "#.##") + " R"
string plan = str.tostring(t1R) + "R" + (nT >= 2 ? " / " + str.tostring(t2R) + "R" : "") + (nT >= 3 ? " / " + str.tostring(t3R) + "R" : "") + (nT >= 4 ? " / " + str.tostring(t4R) + "R" : "") + (lastExit == LE_TRL ? ", last part trails" : lastExit == LE_NONE ? ", last part rides" : "")
string tgtTxt = tr.dir == 0 ? plan : str.tostring(math.min(hits, nT)) + " of " + str.tostring(nT) + " reached (" + plan + ")"
f_cell(0, 0, NAME, fg)
f_cell(1, 0, stateTxt, tr.dir == 1 ? upCol : tr.dir == -1 ? dnCol : fg)
f_cell(0, 1, "Targets", fg)
f_cell(1, 1, tgtTxt, fg)
f_cell(0, 2, "Stop", fg)
f_cell(1, 2, tr.dir == 0 ? "-" : str.tostring(tr.stop, format.mintick), fg)
f_cell(0, 3, k1, fg)
f_cell(1, 3, v1, fg)
f_cell(0, 4, k2, fg)
f_cell(1, 4, v2, fg)
f_cell(0, 5, "Positions taken", fg)
f_cell(1, 5, str.tostring(tr.count), fg)
f_cell(0, 6, "Net result", fg)
f_cell(1, 6, str.tostring(strategy.netprofit / strategy.initial_capital * 100.0, "#.#") + "% at " + str.tostring(riskPct, "#.##") + "% risk", fg)
f_cell(0, 7, "Profit factor", fg)
f_cell(1, 7, strategy.grossloss > 0 ? str.tostring(strategy.grossprofit / strategy.grossloss, "#.##") : "-", fg)
f_dash("Channel", str.tostring(entryLen) + "-bar breakout, " + str.tostring(exitLen) + "-bar exit", "Base EMA", not useBase ? "off" : close > emaB ? "above: longs only" : "below: shorts only")A confirmed close must newly cross beyond the preceding 55-bar high for a long or low for a short. By default, the close must also be on the matching side of the 200-period base EMA, and the strategy must be eligible to open a position.
No. Although Target 3 defaults to 5.0R, the default last-exit setting gives the final portion no fixed target; it can leave through the stop or the enabled 20-bar exit-channel rule. Select “Its fixed target” to place an order at the last active target.
The code names no preferred market or timeframe. Channel lengths are measured in chart bars, so changing the timeframe changes the period covered; the chart also needs enough history to calculate the channels, EMA, and ATR.
The breakout channels exclude the current bar, and entry and exit-channel decisions require confirmed closes. Entries are market orders submitted on the signal bar and normally filled at the next bar’s open; historical intrabar stop and target fills depend on TradingView’s fill simulation.
The script calls `alert()` when it submits an entry and when its high/low checks first mark targets 1–3 as reached. A target-touch alert is not a separate confirmation that the corresponding exit order filled.
No. This is technical documentation, not financial advice. Use TradingView’s Strategy Tester as the source of truth for this strategy’s historical simulated results on your selected symbol and settings; those results are not live verification.
Describe the change in plain English and AlgoNexta rebuilds it as a fresh Pine v6 script — with its own explanation, evidence, and walkthrough.
Build your own versionEducational content only — not financial advice. TradingView is the source of truth for live data, compilation, and Strategy Tester results.
Buy gold when the daily close breaks above the highest high of the last 55 days. Sell when it breaks below the lowest low of the last 55 days. Only buy when the close is above the 200-day EMA, and only sell when it is below it.
Trend filter added: +24.35%, 36 trades, 55.6% winners, profit factor 2.32, max drawdown 3.41%. Then, in the backtest panel, split exits 30% at 1.5R, 30% at 3R, 40% at 5R with the stop to entry after TP1: +19.75%, 24 trades, 58.3% winners, profit factor 2.65, max drawdown 3.04%.
Studio builds the core rule from the prompt. The published script can add more on top, such as its exit and risk settings; the description above lists them.