SML Dual Market
Instant download · 7-day refunds on every product — see the refund policy · Veteran-owned small business
MA Cross Regime Strategy — Free Pine Script v6 Strategy for TradingViewMA Cross Regime Strategy — Free Pine Script v6 Strategy for TradingView — ZIP bundle cover

MA Cross Regime Strategy — Free Pine Script v6 Strategy for TradingView

Free
Get it free
Free · instant download on claim · no account · signed receipt — how buying works →
Sold byScript Master Labs LLC (SDVOSB · UEI G24VZA4RLMK3 · CAGE 21U51)
File checkedWe test-download every product before it's listed (last checked Dec 4, 2026).
UpdatedDec 4, 2026
No account needed. Your download link appears right after checkout — bookmark it.
You get exactly this
free-ma-cross-regime.zip — complete Pine Script v6 strategy source + install README + free license (free edition)
What's inside
ZIP — Pine Script v6 strategy source (.pine), install README, free license
  • ma-cross-regime.pine — the complete Pine Script v6 strategy source
  • README-FIRST.md — what it does and how to install it
  • FREE-LICENSE.md — the free-edition license terms
Delivered as one download, the moment you claim it — no payment, no account.

About this product

MA Cross Regime Strategy is a free Pine Script v6 strategy by Script Master Labs. It backtests moving-average cross regimes — 3-EMA and 6-EMA stack rule sets — with trend filters and a trailing ATR stop. The complete source is printed in full on this page and in the free download — paste it into TradingView's Pine Editor and it runs on TradingView's free plan. No payment, no account, no subscription.

What it computes, in its own terms: it moving-average cross regimes under two EMA length sets — a 3-EMA set (13/55/174) and a 6-EMA stack (1/13/55/123/178/247): it enters long or short on crosses only when the trend filters hold (price and the fast EMAs above the long EMA, which must itself be rising; the short side mirrors it), exits on the opposite cross, and trails an ATR stop with an optional ATR take-profit. Its dashboard reports the regime, the stack, trades, win rate, profit factor, net return and maximum drawdown of the user's own backtest. It is a screening and education tool, not financial advice, and a backtest is not evidence of future results.

How to use it

Open TradingView's Pine Editor, create a new blank script, paste the source, save, and click Add to chart. Because it is a strategy, open the Strategy Tester panel to run the backtest and read its dashboard. Adjust the inputs from the gear icon. The full source is printed on this page below, and the free download carries the same source file with an install README and the free-edition license.

Free — and there is no paid edition

This strategy is published free. There is no paid edition of it on Dual Market; the complete source is the whole product, printed on this page and in the free download.

More free tools — free Pine Script v6 indicators and strategies, free trading calculators and a free x402 pre-payment trust check — are collected on the Free Tools hub. Educational software, not financial advice: it measures and draws a stated rule; it does not predict price and shows no win rate.

The complete Pine Script v6 source — free, on this page

MA Cross Regime Strategy is a free Pine Script v6 strategy by Script Master Labs. It backtests moving-average cross regimes — 3-EMA and 6-EMA stack rule sets — with trend filters and a trailing ATR stop. The complete source is printed in full on this page and in the free download — paste it into TradingView's Pine Editor and it runs on TradingView's free plan. No payment, no account, no subscription.

Copy it into TradingView's Pine Editor (new blank indicator → paste → Save → Add to chart), or claim the free download above for the same source as a file with an install README. Educational software, not financial advice.

//@version=6
// ============================================================
// MA Cross Regime Strategy — 3ema / 6ema
// ScriptMasterLabs — screening/education tool, not financial advice.
// ------------------------------------------------------------
// 3ema (13/55/174): long when 13 crosses above 55, only if price,
//   13 and 55 are all above the 174 and the 174 is rising. Short = mirror.
// 6ema (1/13/55/123/178/247): long when 1 crosses above 13, only if
//   the full stack 1>13>55>123>178>247 holds and the 247 is rising.
//   Short = mirror.
// Trailing ATR stop, exit on opposite cross, optional ATR take-profit.
// Dashboard: regime, stack, trades, win rate, profit factor, net %, max DD.
// Robustness test: flip "Length Set" through all five sets on AMC/GME
// 4H and Daily and compare profit factor. Close PFs = solid, one
// standout = overfit.
// ============================================================
strategy("MA Cross Regime [SML]", shorttitle="MA-X Regime",
     overlay=true, initial_capital=10000,
     default_qty_type=strategy.percent_of_equity, default_qty_value=100,
     commission_type=strategy.commission.percent, commission_value=0.05,
     pyramiding=0, calc_on_every_tick=false)

// ---------------- Length sets ----------------
grpLen = "Length sets"
setChoice = input.string("3ema (13/55/174)", "Length Set", group=grpLen,
     options=["3ema (13/55/174)", "6ema (1/13/55/123/178/247)", "Set 3", "Set 4", "Set 5"])
is6 = setChoice == "6ema (1/13/55/123/178/247)"
// Fill sets 3-5 with your alternates (robustness test)
f2 = input.int(13, "Set 2 — fast",  group=grpLen, minval=1)
m2 = input.int(55, "Set 2 — mid",   group=grpLen, minval=1)
s2 = input.int(174, "Set 2 — slow", group=grpLen, minval=1)
f3 = input.int(13, "Set 3 — fast",  group=grpLen, minval=1)
m3 = input.int(55, "Set 3 — mid",   group=grpLen, minval=1)
s3 = input.int(174, "Set 3 — slow", group=grpLen, minval=1)
f4 = input.int(13, "Set 4 — fast",  group=grpLen, minval=1)
m4 = input.int(55, "Set 4 — mid",   group=grpLen, minval=1)
s4 = input.int(174, "Set 4 — slow", group=grpLen, minval=1)
f5 = input.int(13, "Set 5 — fast",  group=grpLen, minval=1)
m5 = input.int(55, "Set 5 — mid",   group=grpLen, minval=1)
s5 = input.int(174, "Set 5 — slow", group=grpLen, minval=1)

fastLen = setChoice == "3ema (13/55/174)" ? 13  : setChoice == "Set 2" ? f2 : setChoice == "Set 3" ? f3 : setChoice == "Set 4" ? f4 : f5
midLen  = setChoice == "3ema (13/55/174)" ? 55  : setChoice == "Set 2" ? m2 : setChoice == "Set 3" ? m3 : setChoice == "Set 4" ? m4 : m5
slowLen = setChoice == "3ema (13/55/174)" ? 174 : setChoice == "Set 2" ? s2 : setChoice == "Set 3" ? s3 : setChoice == "Set 4" ? s4 : s5

// ---------------- Risk ----------------
grpRisk = "Risk"
atrLen  = input.int(14, "ATR length", group=grpRisk, minval=1)
atrMult = input.float(3.0, "Trailing stop × ATR", group=grpRisk, minval=0.1, step=0.1)
useTP   = input.bool(false, "Use take-profit", group=grpRisk)
tpMult  = input.float(2.0, "Take-profit × ATR", group=grpRisk, minval=0.1, step=0.1)

// ---------------- Calcs ----------------
// 3ema lines (fast/mid/slow lengths from Length Set)
emaFast = ta.ema(close, fastLen)
emaMid  = ta.ema(close, midLen)
emaSlow = ta.ema(close, slowLen)
// 6ema lines (fixed)
e1   = ta.ema(close, 1)
e13  = ta.ema(close, 13)
e55  = ta.ema(close, 55)
e123 = ta.ema(close, 123)
e178 = ta.ema(close, 178)
e247 = ta.ema(close, 247)
atr  = ta.atr(atrLen)

// Chop gate: ADX trend confirmation
[plusDI, minusDI, adxV] = ta.dmi(adxLen, adxLen)
gateOK = not useGate or adxV >= adxMin

// Unified signal/filter roles per mode
sigFast = is6 ? e1   : emaFast   // cross line: 1 (6ema) or fast (3ema)
sigMid  = is6 ? e13  : emaMid    // cross line: 13 (6ema) or mid (3ema)
regSlow = is6 ? e247 : emaSlow   // regime line: 247 (6ema) or slow (3ema)

slowRising  = regSlow > regSlow[1]
slowFalling = regSlow < regSlow[1]

bullRegime = close > regSlow and slowRising
bearRegime = close < regSlow and slowFalling

crossUp   = ta.crossover(sigFast, sigMid)
crossDown = ta.crossunder(sigFast, sigMid)

// 3ema: price, fast, mid all above slow. 6ema: full 6-stack above regime.
bullStack = is6 ? (e1 > e13 and e13 > e55 and e55 > e123 and e123 > e178 and e178 > e247) \
                : (close > emaSlow and emaFast > emaSlow and emaMid > emaSlow)
bearStack = is6 ? (e1 < e13 and e13 < e55 and e55 < e123 and e123 < e178 and e178 < e247) \
                : (close < emaSlow and emaFast < emaSlow and emaMid < emaSlow)

longCond  = crossUp   and bullStack and slowRising and gateOK
shortCond = crossDown and bearStack and slowFalling and gateOK

// ---------------- Plots ----------------
slowColor = bullRegime ? color.new(#00c853, 0) : bearRegime ? color.new(#ff4fa3, 0) : color.new(#9e9e9e, 0)
if is6
    plot(e1,   "1",   color.new(#2962ff, 0), 1)
    plot(e13,  "13",  color.new(#00bcd4, 0), 1)
    plot(e55,  "55",  color.new(#ff9800, 0), 2)
    plot(e123, "123", color.new(#ab47bc, 0), 1)
    plot(e178, "178", color.new(#78909c, 0), 1)
    plot(e247, "247 (regime)", slowColor, 3)
else
    plot(emaFast, "Fast", color.new(#2962ff, 0), 2)
    plot(emaMid,  "Mid",  color.new(#ff9800, 0), 2)
    plot(emaSlow, "Slow (regime)", slowColor, 3)

plotshape(longCond,  "Long signal",  style=shape.triangleup,   location=location.belowbar, color=color.new(#00c853, 0), size=size.small)
plotshape(shortCond, "Short signal", style=shape.triangledown, location=location.abovebar, color=color.new(#ff4fa3, 0), size=size.small)

// ---------------- Orders ----------------
// Exit on the opposite cross first, then (re)enter
if crossDown
    strategy.close("Long", comment="X-down")
if crossUp
    strategy.close("Short", comment="X-up")
if longCond
    strategy.entry("Long", strategy.long, comment="LONG")
if shortCond
    strategy.entry("Short", strategy.short, comment="SHORT")

// Trailing ATR stop (chandelier style, ratchets only in our favor)
var float trailLong  = na
var float trailShort = na
if strategy.position_size > 0
    float nl = close - atr * atrMult
    trailLong  := na(trailLong)  ? nl : math.max(trailLong, nl)
    trailShort := na
else if strategy.position_size < 0
    float ns = close + atr * atrMult
    trailShort := na(trailShort) ? ns : math.min(trailShort, ns)
    trailLong  := na
else
    trailLong  := na
    trailShort := na

longTP  = useTP ? strategy.position_avg_price + tpMult * atr : na
shortTP = useTP ? strategy.position_avg_price - tpMult * atr : na
strategy.exit("L-Exit", "Long",  stop=trailLong,  limit=longTP,  comment="L-Stop")
strategy.exit("S-Exit", "Short", stop=trailShort, limit=shortTP, comment="S-Stop")

// ---------------- Alerts ----------------
if longCond
    alert("LONG " + syminfo.ticker + " " + timeframe.period + " @ " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)
if shortCond
    alert("SHORT " + syminfo.ticker + " " + timeframe.period + " @ " + str.tostring(close, format.mintick), alert.freq_once_per_bar_close)

// ---------------- Dashboard ----------------
var table dash = table.new(position.top_right, 2, 9, border_width=1, border_color=color.new(#444444, 0))
if barstate.islast
    nTrades  = strategy.closedtrades
    nWins    = strategy.wintrades
    winRate  = nTrades > 0 ? nWins / nTrades * 100 : na
    grossP   = strategy.grossprofit
    grossL   = strategy.grossloss
    pf       = grossL < 0 ? grossP / math.abs(grossL) : nTrades > 0 ? na : na
    netPct   = strategy.netprofit / strategy.initial_capital * 100
    ddPct    = strategy.max_drawdown / strategy.initial_capital * 100
    regime   = bullRegime ? "BULL 🟢" : bearRegime ? "BEAR 🌸" : "NEUTRAL ⚪"
    stack    = is6 ? (bullStack ? "1>13>55>123>178>247 ▲" : bearStack ? "1<13<55<123<178<247 ▼" : "MIXED ▬") \
                   : (emaFast > emaMid and emaMid > emaSlow ? str.tostring(fastLen) + ">" + str.tostring(midLen) + ">" + str.tostring(slowLen) + " ▲" : emaFast < emaMid and emaMid < emaSlow ? str.tostring(fastLen) + "<" + str.tostring(midLen) + "<" + str.tostring(slowLen) + " ▼" : "MIXED ▬")
    hdr      = is6 ? "MA-X 6ema" : "MA-X " + str.tostring(fastLen) + "/" + str.tostring(midLen) + "/" + str.tostring(slowLen)

    table.cell(dash, 0, 0, hdr,                 text_color=color.white, bgcolor=color.new(#1a1a2e, 0), text_size=size.small)
    table.cell(dash, 1, 0, regime,              text_color=color.white, bgcolor=color.new(#1a1a2e, 0), text_size=size.small)
    table.cell(dash, 0, 1, "Stack",             text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 1, stack,               text_color=color.white, text_size=size.small)
    table.cell(dash, 0, 2, "Trades",            text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 2, str.tostring(nTrades), text_color=color.white, text_size=size.small)
    table.cell(dash, 0, 3, "Win rate",          text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 3, na(winRate) ? "—" : str.tostring(winRate, "#.#") + "%", text_color=color.white, text_size=size.small)
    table.cell(dash, 0, 4, "Profit factor",     text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 4, na(pf) ? "—" : str.tostring(pf, "#.##"), text_color=color.white, text_size=size.small)
    table.cell(dash, 0, 5, "Net %",             text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 5, (netPct >= 0 ? "+" : "") + str.tostring(netPct, "#.#") + "%",
        text_color=netPct >= 0 ? color.new(#00c853, 0) : color.new(#ff4fa3, 0), text_size=size.small)
    table.cell(dash, 0, 6, "Max drawdown",      text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 6, "-" + str.tostring(ddPct, "#.#") + "%", text_color=color.new(#ff9800, 0), text_size=size.small)
    table.cell(dash, 0, 7, "Set",               text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 7, setChoice,           text_color=color.white, text_size=size.small)
    table.cell(dash, 0, 8, "ADX gate",          text_color=color.new(#bbbbbb, 0), text_size=size.small)
    table.cell(dash, 1, 8, not useGate ? "OFF" : str.tostring(adxV, "#.#") + (gateOK ? " ✓" : " ✗"),
        text_color=not useGate ? color.new(#bbbbbb, 0) : gateOK ? color.new(#00c853, 0) : color.new(#ff9800, 0), text_size=size.small)
Frequently paired

Questions about this product

Is there a free Pine Script strategy for moving-average cross regimes on TradingView?

Yes. Script Master Labs publishes this MA Cross Regime Strategy as a free Pine Script v6 download on SML Dual Market (https://dual.scriptmasterlabs.com/product/free-ma-cross-regime). The complete source is printed in full on the product page and in the free download — no payment, no account, no subscription.

How do I use the MA Cross Regime Strategy?

Open TradingView's Pine Editor, create a new blank script, paste the source, click Save, then Add to chart. Adjust the inputs from the gear icon. Because it is a strategy, open the Strategy Tester panel to run the backtest. TradingView's first-steps page shows where the editor opens: https://tradingview.com/pine-script-docs/primer/first-steps

Does it work on TradingView's free plan?

Yes. Paste the source into TradingView's Pine Editor and add it to your chart; the free plan runs custom indicators and strategies.

Is there a paid edition with more in it?

No. This script is published free and there is no paid edition of it on Dual Market — the complete source is the whole product.

Does the strategy guarantee a profit?

No. It is a screening and backtesting tool: it applies stated rules and reports the results of your own test. A backtest describes the past under those rules; it is not evidence of future results. This is educational software, not financial advice.