本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PINEDIGGA
//@version=6
// $$$ MOMENTUM DIGGA $$$ v1.0 — Intraday Momentum (Noise Area Breakout), built and measured on NQ futures.
// Idea: Zarattini, Aziz & Barbon (2024), "Beat the Market: An Effective Intraday Momentum Strategy".
// This is an independent clean-room build of that rule; the trades were checked one by one against an
// offline reference on CME NQ 1-minute data.
//
// WHAT TO EXPECT (CME NQ 1m, costs included — read this before using it):
// • Low win rate (~40%). Most days are small losses or small wins.
// • The profit comes from a handful of strong trend days per year; without the 5 best trades every
// tested window is negative. Skipping signals after a losing streak is exactly how you miss them.
// • You will see clusters of quick trades that get stopped out. They are the price of the rule: trades
// shorter than 30 minutes lose ~20 pt on average, but you only know a trade was short after it closed.
// Re-entries pay overall (2nd trade of the day +3.1 pt, after a stop +2.6, after a TM exit +2.9, net of
// cost, 2010-26); capping at 2 trades a day would have removed +596 pt. Don't skip them by hand.
// • Drawdowns are deep relative to the yearly result, and 2010-16 was negative after costs.
// • Past performance is not a promise. Size small (e.g. 1 MNQ) and treat it as a trend-day participant.
// • The default backtest charges 3 ticks of slippage per side (1.5 NQ points round trip).
//
// TREND MAGIC 15m — THE DEFAULT IS A FORWARD TEST (set "Trend Magic 15m" to Off for the original rule)
// • Default: trade only in the direction of the last closed 15m Trend Magic (CCI 20, ATR 5, ×1), and exit
// when a 5m candle closes on the wrong side of it. This was the best version of the last years:
// 2025-26 +18.1 pt/trade vs +9.1 without it, drawdown 1,216 vs 1,495 pt
// 2022-25 +8.6 pt/trade vs +9.3 (slightly worse)
// 2010-21 +1.1 pt/trade vs +1.5 (worse)
// 2010-26 PF 1.27 vs 1.25, max drawdown 1,540 vs 2,116 pt; it keeps the big trend days.
// • It did NOT pass our pre-registered test, because 2010-21 is worse. It ships as a forward test: we keep
// it on and publish how it does on new data. The original rule is one click away.
//
// THE RULE (defaults = the measured NQ settings; every number below is an input)
// • Session 09:30-16:00 New York, weekdays. A day counts only if it has a bar that starts at the open and
// a bar that ends at the close (half days do not count and do not feed the lookback).
// • σ(t) = mean over the 14 previous counted days of |close at time t ÷ that day's open − 1|.
// • Upper = max(today's open, previous day's close) × (1 + σ); Lower = min(same two) × (1 − σ).
// • VWAP = Σ hlc3·volume ÷ Σ volume over today's session bars up to the check.
// • Checks only every 30 minutes (10:00, 10:30 … 15:30, on the close of the bar that ends there):
// long if close > max(Upper, VWAP), short if close < min(Lower, VWAP), else flat.
// A change of state is a market order at the next bar's open (long → flat is the trailing stop
// max(Upper, VWAP), checked only at the check times; long → short reverses).
// • Everything is closed at the session close. Nothing is held overnight.
// Use a 5-minute chart (same trades as 1m, longer history). Trend Magic 15m needs a 1m or 5m chart.
strategy("$$$ INTRADAY MOMENTUM DIGGA $$$ v1.0 - Noise Area Breakout", shorttitle = "$$$ MOMENTUM DIGGA $$$ v1.0", overlay = true, initial_capital = 100000,
default_qty_type = strategy.fixed, default_qty_value = 1, commission_type = strategy.commission.cash_per_contract,
commission_value = 0, slippage = 3, process_orders_on_close = false, pyramiding = 0, max_bars_back = 500,
margin_long = 0, margin_short = 0)
const string BUILD = "MOMENTUM-1.0 b7"
const string G_TR = "⚙️ Trade"
const string G_RULE = "📐 Rule (defaults = the measured NQ settings)"
const string G_TM = "🧲 Trend Magic 15m (forward test)"
const string G_VIS = "🎨 Visuals"
const string G_AL = "🛎️ Alerts"
qtyIn = input.float(1.0, "Size (contracts / lots)", minval = 0.0001, group = G_TR, display = display.none)
dirIn = input.string("Both", "Direction", options = ["Both", "Long only", "Short only"], group = G_TR, display = display.none)
sessIn = input.session("0930-1600", "Session", group = G_RULE, tooltip = "Regular session of the instrument, in the timezone below. Default = US cash session 09:30-16:00 New York.", display = display.none)
TZ = input.string("America/New_York", "Timezone", options = ["America/New_York", "America/Chicago", "Europe/London", "Europe/Berlin", "Europe/Athens", "Asia/Tokyo", "Asia/Hong_Kong", "Australia/Sydney", "UTC"], group = G_RULE, display = display.none)
LOOK = input.int(14, "Noise lookback (days)", minval = 3, maxval = 60, group = G_RULE, tooltip = "The band at each check time = average absolute move from the open at that same time over this many previous full sessions. Measured: 14.", display = display.none)
bandMult = input.float(1.0, "Band width ×", minval = 0.25, maxval = 4.0, step = 0.05, group = G_RULE, tooltip = "Multiplies the noise band. Higher = fewer, later entries. Measured: 1.0.", display = display.none)
CHK = input.int(30, "Check every (minutes)", options = [15, 30, 60], group = G_RULE, tooltip = "Signals are evaluated only at these clock marks after the open (10:00, 10:30 … for 30). The chart timeframe must divide it. Measured: 30.", display = display.none)
useVwap = input.bool(true, "VWAP filter + trailing stop", group = G_RULE, tooltip = "Long needs close above BOTH the upper band and VWAP; the exit is the higher of the two. Off = band only. Measured: on.", display = display.none)
useGap = input.bool(true, "Anchor band to previous close (gap)", group = G_RULE, tooltip = "Upper uses max(today's open, yesterday's close), lower uses min — a gap must be overcome first. Off = today's open only. Measured: on.", display = display.none)
skipHol = input.bool(true, "Skip US holidays / early closes", group = G_RULE, tooltip = "For US index futures/CFDs: no trading and no lookback contribution on exchange holidays and half days. Turn off for non-US markets.", display = display.none)
tmMode = input.string("Filter + 5m exit", "Trend Magic 15m", options = ["Filter + 5m exit", "Filter + 15m exit", "Filter only", "15m exit only", "Off"], group = G_TM, tooltip = "15m Trend Magic (CCI 20, ATR 5, ×1) built from the chart's own bars. Filter = a long needs the close above the last closed 15m Trend Magic, a short below; otherwise flat. 5m exit = close the trade when a 5m candle closes on the wrong side of it; 15m exit = when a 15m candle closes on the wrong side of its own Trend Magic. Measured on NQ futures, 1.5 pt cost, pt/trade 2010-21 · 2022-25 · 2025-26, then 2010-26 PF and max drawdown:\n• Filter + 5m exit (default): +1.1 · +8.6 · +18.1 · PF 1.27 · DD 1,540\n• Filter + 15m exit: +1.2 · +9.2 · +16.0 · PF 1.27 · DD 1,759\n• Filter only: +1.4 · +9.0 · +12.9 · PF 1.25 · DD 2,116\n• 15m exit only: +1.0 · +8.4 · +13.3 · PF 1.25 · DD 1,764\n• Off (original rule): +1.5 · +9.3 · +9.1 · PF 1.25 · DD 2,116\nThe default is the best of the last years but worse in 2010-21, so it failed our pre-registered test and ships as a forward test. Needs a 1m or 5m chart.", display = display.none)
showTm = input.bool(true, "Show the 15m Trend Magic line", group = G_TM, display = display.none)
shadeTm = input.bool(true, "Shade between Trend Magic and price", group = G_TM, display = display.none)
showBand = input.bool(true, "Show noise band + VWAP", group = G_VIS, display = display.none)
fillBand = input.bool(true, "Soft glow inside the band", group = G_VIS, display = display.none)
showStop = input.bool(false, "Show the trailing stop", group = G_VIS, tooltip = "The stop is the upper band or VWAP (long) / lower band or VWAP (short), so it is already on the chart; this only highlights it.", display = display.none)
shadePos = input.bool(false, "Shade the background while in a trade", group = G_VIS, display = display.none)
autoCol = input.bool(true, "Automatic colours (follow chart background)", group = G_VIS, display = display.none)
uCol = input.color(#26c281, "Colours: long · short · VWAP", inline = "col", group = G_VIS, display = display.none)
dCol = input.color(#ff5c6c, "", inline = "col", group = G_VIS, display = display.none)
vCol = input.color(#ffb84d, "", inline = "col", group = G_VIS, display = display.none)
showTbl = input.bool(true, "Show status table", group = G_VIS, display = display.none)
tblPosIn = input.string("Top right", "Table position · size", options = ["Top right", "Top left", "Bottom right", "Bottom left"], inline = "tb", group = G_VIS, display = display.none)
tblSzIn = input.string("Small", "", options = ["Tiny", "Small", "Normal"], inline = "tb", group = G_VIS, display = display.none)
alertsOn = input.bool(true, "Alerts (Any alert() function call)", group = G_AL, display = display.none)
OPEN_M = int(str.tonumber(str.substring(sessIn, 0, 2))) * 60 + int(str.tonumber(str.substring(sessIn, 2, 4)))
CLOSE_M = int(str.tonumber(str.substring(sessIn, 5, 7))) * 60 + int(str.tonumber(str.substring(sessIn, 7, 9)))
NCHK = math.max(1, int((CLOSE_M - OPEN_M - 1) / CHK)) // checks at open+CHK … before the close
allowL = dirIn != "Short only"
allowS = dirIn != "Long only"
tSz = tblSzIn == "Tiny" ? size.tiny : tblSzIn == "Normal" ? size.normal : size.small
// ── bg-aware palette ──
bgL = 0.299 * color.r(chart.bg_color) + 0.587 * color.g(chart.bg_color) + 0.114 * color.b(chart.bg_color)
isDark = bgL <= 128
cUp = autoCol ? (isDark ? #26c281 : #0f9854) : uCol
cDn = autoCol ? (isDark ? #ff5c6c : #d2283c) : dCol
cVw = autoCol ? (isDark ? #ffb84d : #b86e00) : vCol
cTxt = isDark ? #e6e6e6 : #1a1a1a
cDim = isDark ? #9aa0aa : #5a5f69
cPanel = isDark ? color.new(#000000, 15) : color.new(#ffffff, 10)
tmOn = tmMode != "Off"
tmBias = tmMode == "Filter + 5m exit" or tmMode == "Filter + 15m exit" or tmMode == "Filter only"
tmEx5 = tmMode == "Filter + 5m exit"
tmEx15 = tmMode == "Filter + 15m exit" or tmMode == "15m exit only"
tfSec = timeframe.in_seconds()
tmTfOk = not tmOn or tfSec == 60 or tfSec == 300
tfOk = timeframe.isintraday and tfSec <= CHK * 60 and (CHK * 60) % tfSec == 0 and CLOSE_M > OPEN_M and tmTfOk
mStart = hour(time, TZ) * 60 + minute(time, TZ)
mEndRaw = hour(time_close, TZ) * 60 + minute(time_close, TZ)
mEnd = mEndRaw == 0 ? 1440 : mEndRaw
dow = dayofweek(time, TZ)
dayKey = year(time, TZ) * 10000 + month(time, TZ) * 100 + dayofmonth(time, TZ)
inRth = tfOk and dow >= dayofweek.monday and dow <= dayofweek.friday and mStart >= OPEN_M and mStart < CLOSE_M
// US exchange holidays and early closes (no 16:00 close on CME equity futures) — the measured run never traded
// them and never counted them in the lookback. A CFD may still print bars on these days; they are skipped.
// Easter by the anonymous Gregorian algorithm (Good Friday = Easter − 2).
nthDow(int y, int m, int wd, int n) =>
first = dayofweek(timestamp(TZ, y, m, 1, 12, 0))
1 + (wd - first + 7) % 7 + 7 * (n - 1)
lastDow(int y, int m, int wd) =>
dim = dayofmonth(timestamp(TZ, y, m + 1, 1, 12, 0) - 86400000)
last = dayofweek(timestamp(TZ, y, m, dim, 12, 0))
dim - (last - wd + 7) % 7
isSkipDay(int y, int m, int d, int wd) =>
a = y % 19
b = int(y / 100)
c = y % 100
h = (19 * a + b - int(b / 4) - int((8 * b + 13) / 25) + 15) % 30
l = (32 + 2 * (b % 4) + 2 * int(c / 4) - h - c % 4) % 7
mm = int((a + 11 * h + 22 * l) / 451)
em = int((h + l - 7 * mm + 114) / 31)
ed = (h + l - 7 * mm + 114) % 31 + 1
gf = dayofmonth(timestamp(TZ, y, em, ed, 12, 0) - 2 * 86400000)
gfm = month(timestamp(TZ, y, em, ed, 12, 0) - 2 * 86400000)
mon = wd == dayofweek.monday
fri = wd == dayofweek.friday
thg = nthDow(y, 11, dayofweek.thursday, 4)
(m == 1 and (d == 1 or (d == 2 and mon))) or (m == 1 and d == nthDow(y, 1, dayofweek.monday, 3))
or (m == 2 and d == nthDow(y, 2, dayofweek.monday, 3)) or (m == gfm and d == gf)
or (m == 5 and d == lastDow(y, 5, dayofweek.monday))
or (y >= 2022 and m == 6 and (d == 19 or (d == 18 and fri) or (d == 20 and mon)))
or (m == 7 and (d == 3 or d == 4 or (d == 5 and mon)))
or (m == 9 and d == nthDow(y, 9, dayofweek.monday, 1))
or (m == 11 and (d == thg or d == thg + 1))
or (m == 12 and (d == 24 or d == 25 or (d == 26 and mon)))
skipDay = skipHol and isSkipDay(year(time, TZ), month(time, TZ), dayofmonth(time, TZ), dow)
// ── Trend Magic 15m from the chart's own bars: clock buckets :00/:15/:30/:45, all hours ──
// A bucket counts as closed on the bar that ends on its boundary (or, if that bar is missing, on the next bar).
tmStep(float h, float l, float c, float pc, float pm, float[] trs, float[] cls) =>
trs.push(na(pc) ? na : math.max(h - l, math.abs(h - pc), math.abs(l - pc)))
if trs.size() > 5
trs.shift()
cls.push(c)
if cls.size() > 20
cls.shift()
float atr = na
if trs.size() == 5
float s = 0.0
for x in trs
s += x
atr := s / 5
float cci = na
if cls.size() == 20
float mu = 0.0
for x in cls
mu += x
mu /= 20
float dv = 0.0
for x in cls
dv += math.abs(x - mu)
dv /= 20
cci := dv > 0 ? (c - mu) / (0.015 * dv) : na
p = nz(pm)
upT = l - atr
dnT = h + atr
not na(cci) and cci >= 0 ? (upT < p ? p : upT) : (dnT > p ? p : dnT)
var float[] tmTr = array.new_float()
var float[] tmCl = array.new_float()
var int bKey = na
var float bH = na
var float bL = na
var float bC = na
var float tmPC = na
var float tm15 = na // last closed 15m Trend Magic
bool tm15Shut = false // a 15m bucket closed on this bar's close
if tmOn
k15 = math.floor(time / 900000)
if not na(bKey) and k15 != bKey and not na(bC)
tm15 := tmStep(bH, bL, bC, tmPC, tm15, tmTr, tmCl)
tmPC := bC
if na(bKey) or k15 != bKey
bKey := k15
bH := high
bL := low
else
bH := math.max(bH, high)
bL := math.min(bL, low)
bC := close
if time_close % 900000 == 0
tm15 := tmStep(bH, bL, bC, tmPC, tm15, tmTr, tmCl)
tmPC := bC
bC := na
tm15Shut := true
var int dKey = na
var bool dayOk = false
var float dOpen = na
var float prevClose = na
var float lastClose = na // 16:00 close of the last counted day
var float cumPV = 0.0
var float cumV = 0.0
var int nextChk = 0
var float[] todayMv = array.new_float(NCHK, na)
var float[] hist = array.new_float() // LOOK rows × NCHK, oldest first
var float ub = na
var float lb = na
var float vw = na
var int want = 0
// a position must never cross 16:00 (early close, missing bars)
if strategy.position_size != 0 and not inRth
strategy.close_all(comment = "Outside session", immediately = true)
if inRth and (na(dKey) or dKey != dayKey)
dKey := dayKey
dayOk := mStart == OPEN_M and not skipDay
dOpen := open
prevClose := lastClose
cumPV := 0.0
cumV := 0.0
nextChk := 0
want := 0
for j = 0 to NCHK - 1
todayMv.set(j, na)
nDays = hist.size() / NCHK
ready = nDays >= LOOK and dayOk and not na(prevClose)
if inRth
v = nz(volume)
cumPV += hlc3 * v
cumV += v
vw := cumV > 0 ? cumPV / cumV : hlc3
// band shown = the one the next check will use
if ready and nextChk < NCHK
float s = 0.0
for r = 0 to LOOK - 1
s += hist.get(r * NCHK + nextChk)
sg = bandMult * s / LOOK
ub := (useGap ? math.max(dOpen, prevClose) : dOpen) * (1 + sg)
lb := (useGap ? math.min(dOpen, prevClose) : dOpen) * (1 - sg)
// Trend Magic exit (before a check at the same time; never on the session-close bar)
if want != 0 and mEnd < CLOSE_M and not na(tm15)
bool ex5 = tmEx5 and time_close % 300000 == 0
bool ex15 = tmEx15 and tm15Shut
if (ex5 or ex15) and (want == 1 ? close < tm15 : close > tm15)
strategy.close_all(comment = "TM", immediately = true)
if alertsOn
alert("MOMENTUM TREND MAGIC EXIT " + syminfo.ticker + " @ " + str.tostring(close, format.mintick)
+ " · TM15 " + str.tostring(tm15, format.mintick), alert.freq_once_per_bar_close)
want := 0
// checks: every half hour whose time this bar's close has reached (a missing bar = last price)
bool didChk = false
while nextChk < NCHK and mEnd >= OPEN_M + CHK * (nextChk + 1)
todayMv.set(nextChk, math.abs(close / dOpen - 1))
if ready
float s = 0.0
for r = 0 to LOOK - 1
s += hist.get(r * NCHK + nextChk)
sg = bandMult * s / LOOK
ub := (useGap ? math.max(dOpen, prevClose) : dOpen) * (1 + sg)
lb := (useGap ? math.min(dOpen, prevClose) : dOpen) * (1 - sg)
didChk := true
nextChk += 1
if didChk
upT = useVwap ? math.max(ub, vw) : ub
dnT = useVwap ? math.min(lb, vw) : lb
cur = want
want := close > upT and allowL ? 1 : close < dnT and allowS ? -1 : 0
if tmBias and want != 0
bs = na(tm15) ? 0 : close > tm15 ? 1 : close < tm15 ? -1 : 0
if want != bs
want := 0
if want != cur
if want == 1
strategy.entry("L", strategy.long, qty = qtyIn, comment = "Long")
else if want == -1
strategy.entry("S", strategy.short, qty = qtyIn, comment = "Short")
else
strategy.close_all(comment = "Stop")
if alertsOn
alert("MOMENTUM " + (want == 1 ? "LONG" : want == -1 ? "SHORT" : "FLAT") + " " + syminfo.ticker
+ " @ next open · close " + str.tostring(close, format.mintick) + " · Upper "
+ str.tostring(ub, format.mintick) + " · Lower " + str.tostring(lb, format.mintick)
+ " · VWAP " + str.tostring(vw, format.mintick), alert.freq_once_per_bar_close)
// the bar that ends at 16:00: close everything at its close, then file the day
if mEnd >= CLOSE_M
if strategy.position_size != 0
strategy.close_all(comment = "Close", immediately = true)
if alertsOn
alert("MOMENTUM SESSION CLOSE " + syminfo.ticker + " @ " + str.tostring(close, format.mintick),
alert.freq_once_per_bar_close)
want := 0
bool full = true
for j = 0 to NCHK - 1
if na(todayMv.get(j))
full := false
if dayOk and full and mEnd == CLOSE_M
for j = 0 to NCHK - 1
hist.push(todayMv.get(j))
while hist.size() > LOOK * NCHK
hist.shift()
lastClose := close
// ── visuals ──
// The band is drawn as a smooth curve: at each check time it sits exactly on the level that check uses, and
// between two checks it runs straight from one to the next. Both ends are known in advance (they come from the
// previous days and today's open), so the curve never looks ahead.
sgAt(int j) =>
float s = 0.0
for r = 0 to LOOK - 1
s += hist.get(r * NCHK + j)
bandMult * s / LOOK
float dU = na
float dL = na
if inRth and ready
sgA = nextChk == 0 ? 0.0 : sgAt(math.min(nextChk, NCHK) - 1)
sgB = nextChk < NCHK ? sgAt(nextChk) : sgA
t0 = OPEN_M + CHK * nextChk
fr = math.max(0.0, math.min(1.0, (mEnd - t0) / CHK))
sgD = sgA + (sgB - sgA) * fr
dU := (useGap ? math.max(dOpen, prevClose) : dOpen) * (1 + sgD)
dL := (useGap ? math.min(dOpen, prevClose) : dOpen) * (1 - sgD)
if mEnd >= CLOSE_M // the closing bar has already filed today into the lookback
dU := dU[1]
dL := dL[1]
dMid = math.avg(dU, dL)
pos = strategy.position_size > 0 ? 1 : strategy.position_size < 0 ? -1 : 0
stopLvl = pos == 1 ? (useVwap ? math.max(ub, vw) : ub) : pos == -1 ? (useVwap ? math.min(lb, vw) : lb) : na
pUb = plot(showBand ? dU : na, "Upper", color.new(cUp, 15), 2, plot.style_linebr, display = display.all - display.status_line)
pLb = plot(showBand ? dL : na, "Lower", color.new(cDn, 15), 2, plot.style_linebr, display = display.all - display.status_line)
pMid = plot(showBand and fillBand ? dMid : na, "Band middle", display = display.none, editable = false)
fill(pUb, pMid, dU, dMid, showBand and fillBand ? color.new(cUp, 80) : na, color.new(cUp, 100), title = "Upper glow")
fill(pMid, pLb, dMid, dL, color.new(cDn, 100), showBand and fillBand ? color.new(cDn, 80) : na, title = "Lower glow")
plot(showBand and inRth and useVwap ? vw : na, "VWAP", color.new(cVw, 25), 1, plot.style_linebr, display = display.all - display.status_line)
plot(showStop and inRth ? stopLvl : na, "Trailing stop", color.new(pos == 1 ? cUp : cDn, 30), 1, plot.style_cross, display = display.all - display.status_line)
tmVis = tmOn and inRth and not na(tm15)
tmAbove = close > tm15
pTm = plot(showTm and tmVis ? tm15 : na, "Trend Magic 15m", color.new(tmAbove ? cUp : cDn, 45), 1, plot.style_linebr, display = display.all - display.status_line)
pPx = plot(shadeTm and tmVis ? close : na, "Price for shade", display = display.none, editable = false)
// strongest next to price, fading towards the Trend Magic line
fill(pPx, pTm, tmAbove ? close : tm15, tmAbove ? tm15 : close, shadeTm and tmVis ? color.new(tmAbove ? cUp : cDn, tmAbove ? 72 : 96) : na,
shadeTm and tmVis ? color.new(tmAbove ? cUp : cDn, tmAbove ? 96 : 72) : na, title = "Trend Magic shade")
bgcolor(shadePos and pos != 0 ? color.new(pos == 1 ? cUp : cDn, 94) : na, title = "Position shade")
var table tb = table.new(tblPosIn == "Top left" ? position.top_left : tblPosIn == "Bottom right" ? position.bottom_right : tblPosIn == "Bottom left" ? position.bottom_left : position.top_right, 2, 7, bgcolor = cPanel, border_width = 1, border_color = cDim)
if showTbl and (barstate.islast or barstate.islastconfirmedhistory)
nextTxt = nextChk < NCHK ? str.format("{0,number,00}:{1,number,00}", (OPEN_M + CHK * (nextChk + 1)) / 60, (OPEN_M + CHK * (nextChk + 1)) % 60) : "Session close"
table.cell(tb, 0, 0, "MOMENTUM DIGGA", text_color = cTxt, text_size = tSz)
table.cell(tb, 1, 0, BUILD, text_color = cDim, text_size = tSz)
table.cell(tb, 0, 1, "Status", text_color = cDim, text_size = tSz)
table.cell(tb, 1, 1, not tmTfOk ? "Trend Magic 15m needs a 1m or 5m chart" : not tfOk ? "Timeframe must divide the check interval" : nDays < LOOK ? str.format("Warm-up {0}/{1} days", nDays, LOOK) : pos == 1 ? "LONG" : pos == -1 ? "SHORT" : "Flat",
text_color = not tfOk ? cDn : pos == 1 ? cUp : pos == -1 ? cDn : cTxt, text_size = tSz)
table.cell(tb, 0, 2, "Next check", text_color = cDim, text_size = tSz)
table.cell(tb, 1, 2, nextTxt, text_color = cTxt, text_size = tSz)
table.cell(tb, 0, 3, "Upper / Lower", text_color = cDim, text_size = tSz)
table.cell(tb, 1, 3, str.tostring(ub, format.mintick) + " / " + str.tostring(lb, format.mintick), text_color = cTxt, text_size = tSz)
table.cell(tb, 0, 4, "VWAP", text_color = cDim, text_size = tSz)
table.cell(tb, 1, 4, str.tostring(vw, format.mintick), text_color = cVw, text_size = tSz)
table.cell(tb, 0, 5, "Trend Magic 15m", text_color = cDim, text_size = tSz)
table.cell(tb, 1, 5, not tmOn ? "Off" : tmMode + " · " + (na(tm15) ? "warming up" : close > tm15 ? "above" : "below"), text_color = not tmOn or na(tm15) ? cDim : close > tm15 ? cUp : cDn, text_size = tSz)
table.cell(tb, 0, 6, "Measured", text_color = cDim, text_size = tSz)
table.cell(tb, 1, 6, tmOn ? "Forward test · see the Trend Magic tooltip" : "NQ PF ≈1.25 after cost · few big days", text_color = cDim, text_size = tSz)