Noon Barbari
Sign up
All posts
walkthroughPublished ·10 min read

Three Pine indicator ports: SuperTrend, Blackflag FTS, Trend Magic

Three open-source trend-following indicators ported from Pine into the platform — what each one actually computes, when to reach for which, and an honest note on tuning.

On this page

Why these three

All three indicators in this release are members of the SuperTrend family — ATR-based trailing bands that flip side when price closes through the active rail. They share a common shape: pick a wick reference (high/low or hl2), offset it by an ATR-scaled multiplier, ratchet the rail in the direction of trend, flip when price crosses. Each variant differs in how it picks the reference, how it scales the offset, and which extra filter it layers on top.

We chose these three because (a) they're some of the most-requested ports from the community, (b) all three have permissive open-source Pine sources we could read and reimplement cleanly, and (c) they cover meaningfully different points on the responsiveness-vs-noise trade-off. SuperTrend is the canonical baseline; Blackflag adds pullback structure; Trend Magic adds a CCI gate.

SuperTrend — the canonical

SuperTrend computes a midline at (high + low) / 2, then offsets it up and down by factor × ATR(atrPeriod) to get the two rails. The active rail ratchets monotonically — once the upper rail moves down it can't move back up, once the lower rail moves up it can't move back down — and price closing through the active rail flips the trend. In Pine this is literally one builtin call.

Pine source for SuperTrend (the function we ported)
// Pine v5
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
plot(direction < 0 ? supertrend : na, "Up trend",   color = color.green)
plot(direction > 0 ? supertrend : na, "Down trend", color = color.red)

Inside noonbarbari you reference it as any other indicator. A minimal long-only trend-follower:

rules.yaml — SuperTrend regime filter + close-on-flip exit
strategy:
  name: supertrend_baseline
  indicators:
    - { id: st, kind: SuperTrend, factor: 3.0, atr_period: 10 }
  rules:
    entry_long:  { type: cross_above, left: close, right: st.lower_band }
    exit_long:   { type: signal, signal: st.flip_to_short }
    entry_short: { type: cross_below, left: close, right: st.upper_band }
    exit_short:  { type: signal, signal: st.flip_to_long }

Blackflag FTS — SuperTrend with Fib pullbacks

Blackflag Futures Trading System keeps SuperTrend's ratcheting trail but replaces standard ATR with a gap-adjusted true range, then layers Fibonacci pullback bands around the active trail to scope entry zones. The intent is to enter on a controlled retracement into the trend rather than at the trail itself, which usually means chasing.

The modified TR and the Fib pullback levels
// Gap-adjusted true range — wider in volatile opens
modTR = max(high - low,
            abs(high - close[1]),
            abs(low  - close[1]),
            abs(open - close[1]))    // adds open-gap term
atr_m = ta.rma(modTR, atrPeriod)

// Bull trail (ratcheted), and Fib pullback zones inside it
bullTrail = max(prevBullTrail, close - factor * atr_m)
ex_786    = bullTrail + 0.786 * (close - bullTrail)
ex_618    = bullTrail + 0.618 * (close - bullTrail)
ex_500    = bullTrail + 0.500 * (close - bullTrail)
// Entry: price retraces into 0.500-0.618 zone while trend is bull

The exit-fib levels (ex_500, ex_618, ex_786) are not standard SuperTrend output — they're the distinguishing feature. In a noonbarbari rule set, you treat them like any other line and combine them with a momentum confirmation (e.g. RSI rising) so you don't catch retracements that are actually trend reversals.

Trend Magic — CCI-gated ATR ratchet

Trend Magic anchors its bands at the wick of the current candle (low for bull, high for bear) rather than at the midline, offsets by coefficient × ATR(period), and uses the sign of CCI(cciPeriod) to decide which band is active. The CCI gate is the distinguishing feature: trend flips don't happen on close-through-rail alone, they need CCI to confirm momentum in the new direction.

Trend Magic — wick-anchored bands with CCI sign gate
cci      = ta.cci(close, cciPeriod)
atr      = ta.sma(ta.tr, period) * coeff
up_band  = low  - atr           // wick-anchored bull rail
dn_band  = high + atr           // wick-anchored bear rail

if cci >= 0
    magic := max(up_band, magic[1])   // ratchet up
    color := color.blue
else
    magic := min(dn_band, magic[1])   // ratchet down
    color := color.red

The wick anchor makes Trend Magic stickier than vanilla SuperTrend — bull rails sit at recent lows, so it takes a real undercut to flip rather than a marginal close-through. Useful on instruments that wick a lot and trap close-based stops; less useful in tight ranging markets where CCI flips repeatedly.

Caveat

Try it on your own data

Every concept above is implemented in the platform. Backtest, walk-forward, paper-trade, then promote to live — same rule set, all stages.

Related reading