Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Maximized Moving Average Crossing (by Coinrule)

A Pine Script v4 strategy built on SMA (close, 50), RSI (close, lengthRSI) and Crossover (MAshort, MAlong). 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 Maximized 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 3 of 3 trades.
How did Maximized Moving Average Crossing (by Coinrule) do on BTCUSDT 1D with default settings?
−6.59%
From 26 Jan 2024 to 21 Oct 2026, over 9 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Maximized 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 Maximized 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 Maximized Moving Average Crossing (by Coinrule) run in Zeal Terminal?
Yes
It compiles in 9 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • 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$996$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 28) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
−6.59%
−$65.85
Buy and hold
+102.5%
same period
Closed trades
9
2 won · 7 lost
Profitable
22.2%
of closed trades
Profit factor
0.69
gross profit ÷ gross loss
Max drawdown
13.25%
−$139.61

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 28, 29. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 28

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

v4 → v5

Verified

Same 9 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 19: sma → ta.sma
  • Line 20: sma → ta.sma
  • Line 23: rsi → ta.rsi
  • Line 26: crossover → ta.crossover
  • Line 27: crossunder → ta.crossunder
  • Line 28: long = true → direction = strategy.long
⋯// © relevantLeader16058-//@version=4+//@version=5strategy(shorttitle='Maximized Moving Average Crossing ',title='Maximized 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='MA short period')-MAlong = sma(close, inlong)+MAlong = ta.sma(close, inlong)-MAshort= sma(close, inshort)+MAshort= ta.sma(close, inshort)// RSI inputs and calculationslengthRSI = (14)-RSI = rsi(close, lengthRSI)+RSI = ta.rsi(close, lengthRSI)RSI_Signal = input(55, title = 'RSI Trigger', minval=1)//Entry and Exit-bullish = crossover(MAshort, MAlong)+bullish = ta.crossover(MAshort, MAlong)-bearish = crossunder(MAshort, MAlong)+bearish = ta.crossunder(MAshort, MAlong)-strategy.entry(id="long", long = true, when = bullish and RSI > RSI_Signal and window())+strategy.entry(id="long", direction = strategy.long, when = bullish and RSI > RSI_Signal and window())strategy.close(id="long", when = bearish and window())⋯

Clean v5

VerifiedDownload the v5 script

Same 9 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 24: input() → input.int()
  • Line 28: when = bullish and RSI > RSI_Signal and window() → if block
  • Line 29: when = bearish and window() → if block
⋯//MA inputs and calculations-inlong=input(50, title='MA long period')+inlong=input.int(50, title='MA long period')-inshort=input(9, title='MA short period')+inshort=input.int(9, title='MA short period')MAlong = ta.sma(close, inlong)⋯RSI = ta.rsi(close, lengthRSI)-RSI_Signal = input(55, title = 'RSI Trigger', minval=1)+RSI_Signal = input.int(55, title = 'RSI Trigger', minval=1)//Entry and Exit⋯bearish = ta.crossunder(MAshort, MAlong)-strategy.entry(id="long", direction = strategy.long, when = bullish and RSI > RSI_Signal and window())+if bullish and RSI > RSI_Signal and window()+    strategy.entry(id="long", direction = strategy.long)-strategy.close(id="long", when = bearish and window())+if bearish and window()+    strategy.close(id="long") ⋯

Does it run in Pine Script v6?

Yes

Same 9 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

⋯// © relevantLeader16058-//@version=5+//@version=6strategy(shorttitle='Maximized Moving Average Crossing ',title='Maximized 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
MA long period50intMAlong
MA short period9intMAshort
RSI Trigger55int · min 1entry long

What it calculates

  • SMA (sma, ta.sma in v5)close, MA long period (50)MAlong · line 19
  • SMA (sma, ta.sma in v5)close, MA short period (9)MAshort · line 20
  • RSI (rsi, ta.rsi in v5)close, lengthRSIRSI · line 23
  • Crossover (crossover, ta.crossover in v5)MAshort, MAlongbullish · line 26
  • Crossunder (crossunder, ta.crossunder in v5)MAshort, MAlongbearish · 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 datainlongMA long periodsetting · 50inshortMA short periodsetting · 9fromYearFrom Yearsetting · 2020fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1thruYearThru Yearsetting · 2112thruMonthThru Monthsetting · 1thruDayThru Daysetting · 1RSI_SignalRSI Triggersetting · 55MAlongSMA→ MAlongMAshortSMA→ MAshortRSIRSI→ RSIbullishCrossover→ bullishbearishCrossunder→ bearishstartstartvaluefinishfinishvalueentry:longOpen longstrategy.entryclose:longClose longstrategy.closeplot:31plotplotplot:32plotplot

Order rules

OrderFires whenBy defaultLine
Open long longbullish and RSI > RSI_Signal and window()On28
Close longbearish and window()On29

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.

3/3trades 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−6.6%+102.5%922%0.6913.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+3.2%+5.5%1030%1.772.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+14.5%+9.8%933%1.949.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+8.8%+8.4%850%3.792.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−11.5%+16.7%1136%0.5617.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+9.2%+21.5%944%2.522.9%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+18.2%+148.3%850%2.996.8%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−2.5%+17.1%1323%0.666.2%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 market20%−$53.26
Sideways market425%$20.93
Falling market333%−$33.24

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

How bad could the drawdown be?

19.8%

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

0%23%
All 9 trades
SideEntryExitBarsP&L
long21 May 2024 71,446.6021 Jun 2024 64,870.0031−$28.16
long22 Jul 2024 68,165.407 Aug 2024 56,022.0016−$52.42
long20 Sep 2024 62,948.0030 Dec 2024 93,738.20101$134.10
long19 Jan 2025 104,556.009 Feb 2025 96,444.8021−$25.10
long17 Sep 2025 116,789.0026 Sep 2025 108,994.009−$21.17
long4 Oct 2025 122,232.0018 Oct 2025 106,432.0014−$39.59
long6 Jan 2026 93,859.7027 Jan 2026 88,347.1021−$17.60
long18 Mar 2026 73,909.4030 Mar 2026 66,010.9012−$30.97
long10 Apr 2026 71,788.0027 May 2026 75,930.0047$15.33

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
Maximized Moving Average Crossing (by Coinrule) this page—v4 strategy−6.6%913.3%
SRJ RSI Outperformer Strategy by Sapt_Jashrsi smav5 strategy+0.6%82.4%
RSI SMA Crossover Strategy by reeesrsi smav5 strategy+39.8%4230.8%
Short In Downtrend Below MA100 (Coinrule) by Coinrulesma rsiv4 strategy−34.5%9945.4%
Simple RSI and SMA Long and Short (by Coinrule) by Coinrulersi smav5 strategy−3.0%217.7%
RSI Mean Reversion Strategy by Zeal Terminalrsi smav5 strategy+2.2%161.6%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 9 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 28) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © relevantLeader16058//@version=4strategy(shorttitle='Maximized Moving Average Crossing ',title='Maximized 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(50, title='MA long period')inshort=input(9, title='MA short period')MAlong = sma(close, inlong)MAshort= sma(close, inshort)// RSI inputs and calculationslengthRSI = (14)RSI = rsi(close, lengthRSI)RSI_Signal = input(55, title = 'RSI Trigger', minval=1)//Entry and Exitbullish = crossover(MAshort, MAlong)bearish = crossunder(MAshort, MAlong)strategy.entry(id="long", long = true, when = bullish and RSI > RSI_Signal and window())strategy.close(id="long", when = bearish and window()) plot(MAshort, color=color.purple, linewidth=2)plot(MAlong, color=color.red, linewidth=2)