Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Mathias & Christer EMA

A Pine Script v4 strategy built on EMA (close, 9), ATR (1) and Barssince (BuyFirstTrigger). It has 8 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays no commission. 3 settings; defaults include Length 9, Source close and Max Loss 3000.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does Mathias & Christer EMA repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Mathias & Christer EMA do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
Can Mathias & Christer EMA be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does Mathias & Christer EMA use a stop loss?
Yes
strategy.exit sets a stop on line 55, 62.
Does Mathias & Christer EMA run in Zeal Terminal?
Yes
It compiles in 40 ms and runs 1,000 bars in 61 ms, in the browser.

BTCUSDT · 1D · default settings

  • buyLow
  • myATR
  • difference
  • emaCurrent
  • ema4h
  • BuySignalOutBarssince
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (3)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$100,000$202,527Equity from $100,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 54, 61) so the engine trades the way the script says.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Likely bug

    ema(src, 1) ignores the settings line 11

    Line 11 hard-codes 1 where line 10 uses “Length”. Changing those settings moves one band but not this one.

    ema(src, 1)ema(src, len)
  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    1 setting has no label

    In the settings dialog maxLoss (line 8) shows an empty name. The labels on this page come from the variable names.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses transp =, which v5 removed line 21

    transp = on line 21, 22, 28, 29. v5 folds the transparency into the colour with color.new(c, transp).

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames ema → ta.ema, atr → ta.atr, barssince → ta.barssince, crossover → ta.crossover, crossunder → ta.crossunder.

v4 → v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 1: //@version=4 → //@version=5
  • Line 5: input(type = input.integer) → input.int()
  • Line 6: input(type = input.source) → input.source()
  • Line 10: ema → ta.ema
  • Line 11: ema → ta.ema
  • Line 15: atr → ta.atr
20 more edits
  • Line 17: barssince → ta.barssince
  • Line 19: crossover → ta.crossover
  • Line 20: barssince → ta.barssince
  • Line 21: transp = 20 → color.new(BuySignalTest and BuySignalTestBarssince[1]>BuyTriggerLineBarssince[1]? color.green : na, 20)
  • Line 22: transp = 80 → color.new(BuyFirstTrigger and not BuyFirstTrigger[1]? color.green : na, 80)
  • Line 24: barssince → ta.barssince
  • Line 26: crossunder → ta.crossunder
  • Line 27: barssince → ta.barssince
  • Line 28: transp = 20 → color.new(SellSignalTest and SellSignalTestBarssince[1]>SellTriggerLineBarssince? color.red : na, 20)
  • Line 29: transp = 80 → color.new(SellFirstTrigger and not SellFirstTrigger[1] and SellTriggerLineBarssince[1]>SellTriggerLineBarssince? color.red : na, 80)
  • Line 44: barssince → ta.barssince
  • Line 45: barssince → ta.barssince
  • Line 45: crossunder → ta.crossunder
  • Line 46: crossunder → ta.crossunder
  • Line 49: barssince → ta.barssince
  • Line 50: barssince → ta.barssince
  • Line 50: crossover → ta.crossover
  • Line 51: crossover → ta.crossover
  • Line 54: strategy.entry(…, true) → strategy.entry(…, strategy.long)
  • Line 61: strategy.entry(…, false) → strategy.entry(…, strategy.short)
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯strategy("Mathias & Christer EMA", shorttitle="M&C_EMA",overlay=true, process_orders_on_close = true, default_qty_type =  strategy.percent_of_equity, default_qty_value = 100)-len = input(9, title="Length", type=input.integer)+len = input.int(9, title="Length")-src = input(close, title="Source", type=input.source)+src = input.source(close, title="Source")//show4h = input(true, title="show 4h", type=input.bool)⋯//ema4h = security(syminfo.ticker, "240", rsi(src, len))-ema4h                   = ema(src, len)+ema4h                   = ta.ema(src, len)-emaCurrent              = ema(src, 1)+emaCurrent              = ta.ema(src, 1)difference              = (emaCurrent - ema4h)/ema4h⋯plot(buyLow?1:0,title="buyLow",display=display.none)-myATR                   = atr(1)+myATR                   = ta.atr(1)BuyFirstTrigger         = (difference>myATR) and (emaCurrent>ema4h) and (difference[1]<myATR[1])-BuyTriggerLineBarssince = barssince(BuyFirstTrigger)+BuyTriggerLineBarssince = ta.barssince(BuyFirstTrigger)BuyTriggerLine          = close[BuyTriggerLineBarssince]-BuySignalTest           = crossover(close[1],BuyTriggerLine) and (BuyTriggerLineBarssince > 6)+BuySignalTest           = ta.crossover(close[1],BuyTriggerLine) and (BuyTriggerLineBarssince > 6)-BuySignalTestBarssince  = barssince(BuySignalTest)+BuySignalTestBarssince  = ta.barssince(BuySignalTest)-bgcolor(BuySignalTest and BuySignalTestBarssince[1]>BuyTriggerLineBarssince[1]? color.green : na, transp=20)+bgcolor(color.new(BuySignalTest and BuySignalTestBarssince[1]>BuyTriggerLineBarssince[1]? color.green : na, 20))-bgcolor(BuyFirstTrigger and not BuyFirstTrigger[1]? color.green : na, transp=80,title="BuyFirstTrigger")+bgcolor(color.new(BuyFirstTrigger and not BuyFirstTrigger[1]? color.green : na, 80),title="BuyFirstTrigger")SellFirstTrigger         = ((difference*-1)>myATR) and (emaCurrent<ema4h)-SellTriggerLineBarssince = barssince(SellFirstTrigger)+SellTriggerLineBarssince = ta.barssince(SellFirstTrigger)SellTriggerLine          = close[SellTriggerLineBarssince]-SellSignalTest           = crossunder(close[1],SellTriggerLine) and (SellTriggerLineBarssince > 6)+SellSignalTest           = ta.crossunder(close[1],SellTriggerLine) and (SellTriggerLineBarssince > 6)-SellSignalTestBarssince  = barssince(SellSignalTest)+SellSignalTestBarssince  = ta.barssince(SellSignalTest)-bgcolor(SellSignalTest and SellSignalTestBarssince[1]>SellTriggerLineBarssince? color.red : na, transp=20)+bgcolor(color.new(SellSignalTest and SellSignalTestBarssince[1]>SellTriggerLineBarssince? color.red : na, 20))-bgcolor(SellFirstTrigger and not SellFirstTrigger[1] and SellTriggerLineBarssince[1]>SellTriggerLineBarssince? color.red : na, transp=80)+bgcolor(color.new(SellFirstTrigger and not SellFirstTrigger[1] and SellTriggerLineBarssince[1]>SellTriggerLineBarssince? color.red : na, 80))plot(myATR,title="myATR",display=display.none)⋯BuySignal       = BuySignalTest and BuySignalTestBarssince[1]>BuyTriggerLineBarssince-BuySignalBarssince = barssince(BuySignal)+BuySignalBarssince = ta.barssince(BuySignal)-BuySignalOutBarssince = barssince(crossunder(close[1],ema4h[1]))+BuySignalOutBarssince = ta.barssince(ta.crossunder(close[1],ema4h[1]))-BuySignalOut   = crossunder(close[1],ema4h[1]) and BuySignalOutBarssince[1]>BuySignalTestBarssince[1]+BuySignalOut   = ta.crossunder(close[1],ema4h[1]) and BuySignalOutBarssince[1]>BuySignalTestBarssince[1]plot(BuySignalOutBarssince,title="BuySignalOutBarssince",display=display.none)SellSignal      = SellSignalTest and SellSignalTestBarssince[1]>SellTriggerLineBarssince-SellSignalBarssince = barssince(ema4h[1]>ema4h[0] and ema4h[1]>80)+SellSignalBarssince = ta.barssince(ema4h[1]>ema4h[0] and ema4h[1]>80)-SellSignalOutBarssince = barssince(crossover(close[1],ema4h[1]))+SellSignalOutBarssince = ta.barssince(ta.crossover(close[1],ema4h[1]))-SellSignalOut   = crossover(close[1],ema4h[1]) and SellSignalOutBarssince[1]>SellSignalTestBarssince[1]+SellSignalOut   = ta.crossover(close[1],ema4h[1]) and SellSignalOutBarssince[1]>SellSignalTestBarssince[1]if BuySignal    strategy.close("short", comment = "Exit short")-    strategy.entry("long", true)+    strategy.entry("long", strategy.long)    strategy.exit("Max Loss", "long", loss = maxLoss)⋯    strategy.close("long", comment = "Exit Long")-    strategy.entry("short", false)+    strategy.entry("short", strategy.short)    strategy.exit("Max Loss", "short", loss = maxLoss)⋯

Clean v5

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 8: input() → input.int()
⋯//show4h = input(true, title="show 4h", type=input.bool)-maxLoss = input(3000)+maxLoss = input.int(3000)//ema4h = security(syminfo.ticker, "240", rsi(src, len))⋯

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Length9int (written input.integer)ema4h
Sourceclosesourceema4h emaCurrent
Max Loss (no label in the script)3000intexit Max Loss

What it calculates

  • EMA (ema, ta.ema in v5)Source (close), Length (9)ema4h · line 10
  • EMA (ema, ta.ema in v5)Source (close), 1emaCurrent · line 11
  • ATR (atr, ta.atr in v5)1myATR · line 15
  • Barssince (barssince, ta.barssince in v5)BuyFirstTriggerBuyTriggerLineBarssince · line 17
  • Barssince (barssince, ta.barssince in v5)BuySignalTestBuySignalTestBarssince · line 20
  • Barssince (barssince, ta.barssince in v5)SellFirstTriggerSellTriggerLineBarssince · line 24
  • Barssince (barssince, ta.barssince in v5)SellSignalTestSellSignalTestBarssince · line 27
  • Barssince (barssince, ta.barssince in v5)BuySignalBuySignalBarssince · line 44
  • Barssince / Crossunder (barssince, ta.barssince in v5)crossunder(close[1],ema4h[1])BuySignalOutBarssince · line 45
  • Barssince / Crossover (barssince, ta.barssince in v5)crossover(close[1],ema4h[1])SellSignalOutBarssince · line 50

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

closecloseprice datalenLengthsetting · 9high · low · closehigh · low · closeprice datalowlowprice dataema4hEMA→ ema4hemaCurrentEMA→ emaCurrentmyATRATR→ myATRBuyTriggerLineBarssinceBarssince→ BuyTriggerLineBarssinceBuySignalTestBarssinceBarssince→ BuySignalTestBarssinceSellTriggerLineBarssinceBarssince→ SellTriggerLineBarssinceSellSignalTestBarssinceBarssince→ SellSignalTestBarssinceBuySignalBarssinceBarssince→ BuySignalBarssinceBuySignalOutBarssinceBarssince / Crossunder→ BuySignalOutBarssinceSellSignalOutBarssinceBarssince / Crossover→ SellSignalOutBarssincedifferencedifferencevalueBuyTriggerLineBuyTriggerLinevalueSellTriggerLineSellTriggerLinevalueBuySignalBuySignalconditionBuySignalOutBuySignalOutconditionSellSignalSellSignalconditionSellSignalOutSellSignalOutconditionbuyLowbuyLowconditionBuyFirstTrigger, SellFirstTriggerBuyFirstTrigger · SellF…2 conditionsBuySignalTestBuySignalTestconditionSellSignalTestSellSignalTestconditionSellSignalBarssinceSellSignalBarssinceconditionclose:shortClose shortstrategy.closeentry:longOpen longstrategy.entryexit:Max Lossexit Max Lossstrategy.exitclose:longClose longstrategy.closeentry:shortOpen shortstrategy.entryplot:14buyLowplotbgcolor:21bgcolorbgcolorbgcolor:22BuyFirstTriggerbgcolorbgcolor:28bgcolorbgcolorbgcolor:29bgcolorbgcolorplot:30myATRplotplot:31differenceplotplot:32emaCurrentplotplot:33ema4hplotplot:34BuyTriggerLineBarssinceplotplot:35BuySignalTestBarssinceplotplot:36BuyTriggerLineplotplot:37SellTriggerLineBarssinceplotplot:38SellSignalTestBarssinceplotplot:39SellTriggerLineplotplot:47BuySignalOutBarssinceplotplotchar:67plotcharplotcharplotchar:68plotcharplotcharplotchar:69plotcharplotcharplotchar:70plotcharplotchar

Order rules

OrderFires whenBy defaultLine
Close shortBuySignalOn53
Open long longBuySignalOn54
Exit Max Loss stopBuySignalOn55
Close longBuySignalOutOn57
Close longSellSignalOn60
Open short shortSellSignalOn61
Exit Max Loss stopSellSignalOn62
Close shortSellSignalOutOn65

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Mathias & Christer EMA this page—v4 strategy0.0%00.0%
Dazzling Bolts by OrcChieftainema atr barssincev4 strategy+8.5%1413.0%
Twin Range Filter Algo by OrcChieftainema atr barssincev4 strategy+48.4%186.8%
Trend Reversal - Potential pressure by BardiaB2atr emav4 strategy+133,960.0%51,504.8%
Simple Ema_ATR Strategy HulkTrading by TheHulkTradingema atrv4 strategy+2.2%1415.6%
Keltner Breakout Strategy by Zeal Terminalema atrv5 strategy+3.5%212.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 40 msWith a workaround 1,000 bars in 61 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 54, 61) so the engine trades the way the script says.

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © mattehalenstrategy("Mathias & Christer EMA", shorttitle="M&C_EMA",overlay=true, process_orders_on_close = true, default_qty_type =  strategy.percent_of_equity, default_qty_value = 100)len = input(9, title="Length", type=input.integer)src = input(close, title="Source", type=input.source)//show4h = input(true, title="show 4h", type=input.bool)maxLoss = input(3000)//ema4h = security(syminfo.ticker, "240", rsi(src, len))ema4h                   = ema(src, len)emaCurrent              = ema(src, 1)difference              = (emaCurrent - ema4h)/ema4hbuyLow                  = low>ema4hplot(buyLow?1:0,title="buyLow",display=display.none)myATR                   = atr(1)BuyFirstTrigger         = (difference>myATR) and (emaCurrent>ema4h) and (difference[1]<myATR[1])BuyTriggerLineBarssince = barssince(BuyFirstTrigger)BuyTriggerLine          = close[BuyTriggerLineBarssince]BuySignalTest           = crossover(close[1],BuyTriggerLine) and (BuyTriggerLineBarssince > 6)BuySignalTestBarssince  = barssince(BuySignalTest)bgcolor(BuySignalTest and BuySignalTestBarssince[1]>BuyTriggerLineBarssince[1]? color.green : na, transp=20)bgcolor(BuyFirstTrigger and not BuyFirstTrigger[1]? color.green : na, transp=80,title="BuyFirstTrigger")SellFirstTrigger         = ((difference*-1)>myATR) and (emaCurrent<ema4h)SellTriggerLineBarssince = barssince(SellFirstTrigger)SellTriggerLine          = close[SellTriggerLineBarssince]SellSignalTest           = crossunder(close[1],SellTriggerLine) and (SellTriggerLineBarssince > 6)SellSignalTestBarssince  = barssince(SellSignalTest)bgcolor(SellSignalTest and SellSignalTestBarssince[1]>SellTriggerLineBarssince? color.red : na, transp=20)bgcolor(SellFirstTrigger and not SellFirstTrigger[1] and SellTriggerLineBarssince[1]>SellTriggerLineBarssince? color.red : na, transp=80)plot(myATR,title="myATR",display=display.none)plot(difference,title="difference",display=display.none)plot(emaCurrent,title="emaCurrent")plot(ema4h,title="ema4h", color=color.purple, linewidth=5)plot(BuyTriggerLineBarssince,title="BuyTriggerLineBarssince",display=display.none)plot(BuySignalTestBarssince,title="BuySignalTestBarssince",display=display.none)plot(BuyTriggerLine,"BuyTriggerLine",color.green,linewidth=5)plot(SellTriggerLineBarssince,title="SellTriggerLineBarssince",display=display.none)plot(SellSignalTestBarssince,title="SellSignalTestBarssince",display=display.none)plot(SellTriggerLine,"SellTriggerLine",color.red,linewidth=5)//--------------------------------------------------//--------------------------------------------------//BuySignal       = BuySignalTest and BuySignalTestBarssince[1]>BuyTriggerLineBarssinceBuySignalBarssince = barssince(BuySignal)BuySignalOutBarssince = barssince(crossunder(close[1],ema4h[1]))BuySignalOut   = crossunder(close[1],ema4h[1]) and BuySignalOutBarssince[1]>BuySignalTestBarssince[1]plot(BuySignalOutBarssince,title="BuySignalOutBarssince",display=display.none)SellSignal      = SellSignalTest and SellSignalTestBarssince[1]>SellTriggerLineBarssinceSellSignalBarssince = barssince(ema4h[1]>ema4h[0] and ema4h[1]>80)SellSignalOutBarssince = barssince(crossover(close[1],ema4h[1]))SellSignalOut   = crossover(close[1],ema4h[1]) and SellSignalOutBarssince[1]>SellSignalTestBarssince[1]if BuySignal    strategy.close("short", comment = "Exit short")    strategy.entry("long", true)    strategy.exit("Max Loss", "long", loss = maxLoss)if BuySignalOut    strategy.close("long", comment = "Exit Long")if SellSignal    // Enter trade and issue exit order on max loss.    strategy.close("long", comment = "Exit Long")    strategy.entry("short", false)    strategy.exit("Max Loss", "short", loss = maxLoss)if SellSignalOut    // Force trade exit.    strategy.close("short", comment = "Exit short")    plotchar(BuySignal, "BuySignal", "⬆", location.belowbar, color.lime,size =size.huge )plotchar(BuySignalOut, "BuySignalOut", "█", location.belowbar, color.lime,size =size.small)plotchar(SellSignal, "SellSignal", "⬇", location.abovebar ,color.red,size =size.huge)plotchar(SellSignalOut, "SellSignalOut", "█", location.abovebar, color.red,size =size.small)