Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Multi Moving Average Crossing (by Coinrule)

A Pine Script v4 strategy built on SMA (close, 100), Crossover (MAmid, MAlong) and Crossunder (MAshort, MAmid). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 30% of equity and pays 0.1% commission. 10 settings; defaults include From Month 1, From Day 1 and From Year 2020.

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 Multi Moving Average Crossing (by Coinrule) repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
How did Multi Moving Average Crossing (by Coinrule) do on BTCUSDT 1D with default settings?
+5.18%
From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Multi Moving Average Crossing (by Coinrule) be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Multi Moving Average Crossing (by Coinrule) use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Multi Moving Average Crossing (by Coinrule) run in Zeal Terminal?
Yes
It compiles in 13 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • 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 (10)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,069$2,025Equity from $1,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 long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 25) so the engine trades the way the script says.
Net profit
+5.18%
$51.83
Buy and hold
+102.5%
same period
Closed trades
4
1 won · 3 lost
Profitable
25.0%
of closed trades
Profit factor
1.86
gross profit ÷ gross loss
Max drawdown
7.11%
−$71.06

One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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.

  • Check

    1 setting does nothing

    “Show Date Range” is declared but never read.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Note

    No slippage

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

  • Note

    Uses an argument v6 removed

    when = on line 25, 28. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 25

    long = on line 25. v5 writes it as direction = strategy.long or strategy.short.

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 sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.
  • 2 strategy calls use the when = argument (line 25, 28). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 6: input(type = input.integer) → input.int()
  • Line 7: input(type = input.integer) → input.int()
  • Line 8: input(type = input.integer) → input.int()
  • Line 9: input(type = input.integer) → input.int()
  • Line 10: input(type = input.integer) → input.int()
8 more edits
  • Line 11: input(type = input.integer) → input.int()
  • Line 12: input(type = input.bool) → input.bool()
  • Line 20: sma → ta.sma
  • Line 21: sma → ta.sma
  • Line 22: sma → ta.sma
  • Line 24: crossover → ta.crossover
  • Line 25: long = true → direction = strategy.long
  • Line 27: crossunder → ta.crossunder
⋯// © Coinrule-//@version=4+//@version=5strategy(shorttitle='Multi Moving Average Crossing',title='Multi Moving Average Crossing (by Coinrule)', overlay=true, initial_capital=1000,  default_qty_type = strategy.percent_of_equity, default_qty_value = 30, commission_type=strategy.commission.percent, commission_value=0.1)//Backtest dates-fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)+fromMonth = input.int(defval = 1,    title = "From Month", minval = 1, maxval = 12)-fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)+fromDay   = input.int(defval = 1,    title = "From Day", minval = 1, maxval = 31)-fromYear  = input(defval = 2020, title = "From Year",       type = input.integer, minval = 1970)+fromYear  = input.int(defval = 2020, title = "From Year", minval = 1970)-thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)+thruMonth = input.int(defval = 1,    title = "Thru Month", minval = 1, maxval = 12)-thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)+thruDay   = input.int(defval = 1,    title = "Thru Day", minval = 1, maxval = 31)-thruYear  = input(defval = 2112, title = "Thru Year",       type = input.integer, minval = 1970)+thruYear  = input.int(defval = 2112, title = "Thru Year", minval = 1970)-showDate  = input(defval = true, title = "Show Date Range", type = input.bool)+showDate  = input.bool(defval = true, title = "Show Date Range")start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window⋯inshort=input(9, title='MAfast')-MAlong = sma(close, inlong)+MAlong = ta.sma(close, inlong)-MAshort= sma(close, inshort)+MAshort= ta.sma(close, inshort)-MAmid= sma(close, inmid)+MAmid= ta.sma(close, inmid)//Entry -bullish = crossover(MAmid, MAlong)+bullish = ta.crossover(MAmid, MAlong)-strategy.entry(id="long", long = true, when = bullish and window())+strategy.entry(id="long", direction = strategy.long, when = bullish and window())//Exit-bearish = crossunder(MAshort, MAmid)+bearish = ta.crossunder(MAshort, MAmid)strategy.close("long", when = bearish and window())⋯

Clean v5

VerifiedDownload the v5 script

Same 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 17: input() → input.int()
  • Line 18: input() → input.int()
  • Line 19: input() → input.int()
  • Line 25: when = bullish and window() → if block
  • Line 28: when = bearish and window() → if block
⋯//MA inputs and calculations-inlong=input(100, title='MAlong')+inlong=input.int(100, title='MAlong')-inmid=input(50, title='MAmid')+inmid=input.int(50, title='MAmid')-inshort=input(9, title='MAfast')+inshort=input.int(9, title='MAfast')MAlong = ta.sma(close, inlong)⋯bullish = ta.crossover(MAmid, MAlong)-strategy.entry(id="long", direction = strategy.long, when = bullish and window())+if bullish and window()+    strategy.entry(id="long", direction = strategy.long)//Exitbearish = ta.crossunder(MAshort, MAmid)-strategy.close("long", when = bearish and window())+if bearish and window()+    strategy.close("long")plot(MAshort, color=color.orange, linewidth=2)⋯

Does it run in Pine Script v6?

Yes

Same 4 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.

Download the v6 script

⋯// © Coinrule-//@version=5+//@version=6strategy(shorttitle='Multi Moving Average Crossing',title='Multi Moving Average Crossing (by Coinrule)', overlay=true, initial_capital=1000,  default_qty_type = strategy.percent_of_equity, default_qty_value = 30, commission_type=strategy.commission.percent, commission_value=0.1)⋯

Settings

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

SettingDefaultType and rangeFeeds
From Month1int (written input.integer) · min 1 · max 12start
From Day1int (written input.integer) · min 1 · max 31start
From Year2020int (written input.integer) · min 1970start
Thru Month1int (written input.integer) · min 1 · max 12finish
Thru Day1int (written input.integer) · min 1 · max 31finish
Thru Year2112int (written input.integer) · min 1970finish
Show Date Rangetrueboolunused
MAlong100intMAlong
MAmid50intMAmid
MAfast9intMAshort

What it calculates

  • SMA (sma, ta.sma in v5)close, MAlong (100)MAlong · line 20
  • SMA (sma, ta.sma in v5)close, MAfast (9)MAshort · line 21
  • SMA (sma, ta.sma in v5)close, MAmid (50)MAmid · line 22
  • Crossover (crossover, ta.crossover in v5)MAmid, MAlongbullish · line 24
  • Crossunder (crossunder, ta.crossunder in v5)MAshort, MAmidbearish · line 27

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 datainlongMAlongsetting · 100inshortMAfastsetting · 9inmidMAmidsetting · 50fromYearFrom Yearsetting · 2020fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1thruYearThru Yearsetting · 2112thruMonthThru Monthsetting · 1thruDayThru Daysetting · 1MAlongSMA→ MAlongMAshortSMA→ MAshortMAmidSMA→ MAmidbullishCrossover→ bullishbearishCrossunder→ bearishstartstartvaluefinishfinishvalueentry:longOpen longstrategy.entryclose:longClose longstrategy.closeplot:29plotplotplot:30plotplotplot:31plotplot

Order rules

OrderFires whenBy defaultLine
Open long longbullish and window()On25
Close longbearish and window()On28

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, and the live replay matched history.

1/1trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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 timingOrders fill at the next bar's open, after the signal bar has closed.

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 1D+5.2%+102.5%425%1.867.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1.1%+5.5%520%0.642.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.3%+9.8%540%0.847.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+7.9%+8.4%425%7.131.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+3.6%+16.7%667%1.3711.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.2%+21.5%425%1.092.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−1.5%+148.3%450%0.625.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−4.2%+17.1%425%0.166.6%8 May 2026 – 21 Oct 2026

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

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market0—$0.00
Sideways market425%$52.14
Falling market0—$0.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

5.7%

The 95th percentile of the worst drawdown when the same 4 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 3.9% to 5.7%; the tick is what actually happened, 3.9%. Order luck alone moves it this much.

0%7%
All 4 trades
SideEntryExitBarsP&L
long22 Jun 2024 64,143.607 Aug 2024 56,022.0046−$38.51
long23 Oct 2024 67,426.0030 Dec 2024 93,738.2068$111.76
long16 May 2025 103,764.0023 Jun 2025 100,964.0038−$9.31
long3 May 2026 78,686.8027 May 2026 75,930.0024−$11.80

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
Multi Moving Average Crossing (by Coinrule) this page—v4 strategy+5.2%47.1%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.2%

Where it runs

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

Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 25) 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.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Coinrule//@version=4strategy(shorttitle='Multi Moving Average Crossing',title='Multi Moving Average Crossing (by Coinrule)', overlay=true, initial_capital=1000,  default_qty_type = strategy.percent_of_equity, default_qty_value = 30, commission_type=strategy.commission.percent, commission_value=0.1)//Backtest datesfromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)fromYear  = input(defval = 2020, title = "From Year",       type = input.integer, minval = 1970)thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)thruYear  = input(defval = 2112, title = "Thru Year",       type = input.integer, minval = 1970)showDate  = input(defval = true, title = "Show Date Range", type = input.bool)start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start windowfinish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish windowwindow()  => time >= start and time <= finish ? true : false       // create function "within window of time"//MA inputs and calculationsinlong=input(100, title='MAlong')inmid=input(50, title='MAmid')inshort=input(9, title='MAfast')MAlong = sma(close, inlong)MAshort= sma(close, inshort)MAmid= sma(close, inmid)//Entry bullish = crossover(MAmid, MAlong)strategy.entry(id="long", long = true, when = bullish and window())//Exitbearish = crossunder(MAshort, MAmid)strategy.close("long", when = bearish and window())plot(MAshort, color=color.orange, linewidth=2)plot(MAmid, color=color.red, linewidth=2)plot(MAlong, color=color.blue, linewidth=2)