Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

MA cross strategy

A Pine Script v5 strategy built on SMA (close, 10), RSI (close, 14) and ATR (14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. It has no settings.

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 MA cross strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
How did MA cross strategy do on BTCUSDT 1D with default settings?
−606.21%
From 26 Jan 2024 to 21 Oct 2026, over 35 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does MA cross strategy run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 35 before, 0 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
Does MA cross strategy use a stop loss?
Yes
strategy.exit sets a stop on line 18, 23.
Does MA cross strategy run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 19 ms, in the browser.

BTCUSDT · 1D · default settings

  • Short SMA
  • Long SMA
  • 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 (0)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$-5,308,350$2,025,273Equity from $1,000,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.
Net profit
−606.21%
−$6,062,140.00
Buy and hold
+102.5%
same period
Closed trades
35
11 won · 24 lost
Profitable
31.4%
of closed trades
Profit factor
0.53
gross profit ÷ gross loss
Max drawdown
656.02%
−$7,005,620.00

One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A short 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

    No commission

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

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

Settings

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

The script declares no settings.

What it calculates

  • SMAclose, 10shortSMA · line 6
  • SMAclose, 30longSMA · line 7
  • RSIclose, 14rsi · line 8
  • ATR14atr · line 9
  • CrossovershortSMA, longSMAlongCondition · line 11
  • CrossundershortSMA, longSMAshortCondition · line 12

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 datahigh · low · closehigh · low · closeprice datahighhighprice datalowlowprice datashortSMASMA→ shortSMAlongSMASMA→ longSMArsiRSI→ rsiatrATR→ atrlongConditionCrossover→ longConditionshortConditionCrossunder→ shortConditionstopLossstopLossvaluetakeProfittakeProfitvalueentry:longOpen longstrategy.entryexit:exitexit exitstrategy.exitentry:shortOpen shortstrategy.entryplot:25Short SMAplotplot:26Long SMAplot

Order rules

OrderFires whenBy defaultLine
Open long longrsi > 50On17
Exit exit stop and limit(longCondition)On18
Open short shortrsi < 50On22
Exit exit stop and limit(shortCondition)On23

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.

9/9trades 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−606.2%+102.5%3531%0.53656.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−46.3%+5.5%3444%0.85104.8%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−11.5%+9.8%3438%0.7921.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−3.1%+8.4%3135%0.725.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.8%+16.7%2650%1.351.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%3047%1.000.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−5.5%+148.3%3030%0.456.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.0%+17.1%3459%2.160.8%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 market1030%−$1,219,100.00
Sideways market1729%−$3,570,040.00
Falling market838%−$1,273,000.00

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

How bad could the drawdown be?

1,803.7%

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

0%2,074%
All 35 trades
SideEntryExitBarsP&L
short17 Apr 2024 63,793.4019 May 2024 66,915.2032−$312,180.00
long19 May 2024 66,915.2016 Jun 2024 66,228.3028−$68,695.00
short16 Jun 2024 66,228.3024 Jun 2024 61,740.608$448,770.00
long20 Jul 2024 66,660.004 Aug 2024 58,171.7015−$848,834.00
short7 Aug 2024 56,022.0023 Aug 2024 63,348.3016−$732,628.00
long27 Aug 2024 62,834.001 Sep 2024 57,534.805−$529,924.00
short5 Sep 2024 57,970.9019 Sep 2024 63,585.9014−$561,496.00
long20 Sep 2024 62,948.0010 Oct 2024 60,636.0020−$231,199.00
short10 Oct 2024 60,636.0015 Oct 2024 66,505.205−$586,919.00
long16 Oct 2024 67,074.1029 Oct 2024 72,329.4013$525,529.00
short27 Dec 2024 95,791.6018 Jan 2025 104,077.0022−$828,587.00
long18 Jan 2025 104,077.003 Feb 2025 92,274.0016−$1,180,350.00
short8 Feb 2025 96,506.8025 Feb 2025 86,625.0017$988,181.00
long28 Mar 2025 87,232.004 Apr 2025 83,213.107−$401,892.00
short4 Apr 2025 83,213.1019 Apr 2025 84,474.7015−$126,161.00
long19 Apr 2025 84,474.7022 Apr 2025 92,008.703$753,403.00
long16 Jun 2025 105,594.0020 Jun 2025 104,659.004−$93,543.00
short20 Jun 2025 104,659.0022 Jun 2025 98,339.402$631,922.00
long1 Jul 2025 107,147.0010 Jul 2025 114,029.009$688,211.00
short5 Aug 2025 115,055.0011 Aug 2025 121,122.006−$606,651.00
long14 Aug 2025 123,306.0019 Aug 2025 113,284.005−$1,002,240.00
long15 Sep 2025 115,268.0025 Sep 2025 110,247.0010−$502,086.00
short29 Sep 2025 112,164.001 Oct 2025 117,033.002−$486,913.00
long4 Oct 2025 122,232.0010 Oct 2025 113,865.006−$836,721.00
short17 Oct 2025 108,194.004 Nov 2025 98,957.0018$923,724.00
short19 Dec 2025 85,516.406 Jan 2026 93,859.7018−$834,330.00
long6 Jan 2026 93,859.7025 Jan 2026 86,528.2019−$733,150.00
short26 Jan 2026 86,670.4030 Jan 2026 81,201.104$546,923.00
short29 Mar 2026 66,377.009 Apr 2026 72,945.9011−$656,887.00
long12 Apr 2026 73,043.2022 Apr 2026 78,692.2010$564,906.00
short22 May 2026 77,615.5028 May 2026 72,801.406$481,409.00
long11 Jul 2026 64,161.703 Aug 2026 63,570.0023−$59,171.00
short3 Aug 2026 63,570.0019 Aug 2026 67,093.7016−$352,365.00
long21 Aug 2026 73,027.0021 Aug 2026 76,979.200$395,221.00
long22 Sep 2026 86,620.0016 Oct 2026 82,245.9024−$437,408.00

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
MA cross strategy this page—v5 strategy−606.2%35656.0%
Estrategia Larry Connors [JoseMetal] by JoseMetalsma rsi atrv5 strategy+2.7%242.4%
3 x EMA + Stochastic RSI + ATR by tomimarsonrsi sma atrv4 strategy−42.3%1844.8%
Atrend by OTS by prim722rsi sma atrv4 strategy+12.1%7634.4%
EMA crossover (daily TF) by tradeswithashishsma rsi atrv5 strategy+11.0%1211.6%
Impulse Strategy Signals V2 by danieljordisma rsi atrv5 strategyNo trades on this market

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 2 strategy calls use the when = argument (line 17, 22). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 17: when = rsi > 50 → if block
  • Line 22: when = rsi < 50 → if block
⋯    takeProfit = high + atr * 2-    strategy.entry("long", strategy.long, 100, when = rsi > 50)+    if rsi > 50+        strategy.entry("long", strategy.long, 100)    strategy.exit("exit", "long", stop=stopLoss, limit=takeProfit)⋯    takeProfit = low - atr * 2-    strategy.entry("short", strategy.short, 100, when = rsi < 50)+    if rsi < 50+        strategy.entry("short", strategy.short, 100)    strategy.exit("exit", "short", stop=stopLoss, limit=takeProfit)⋯

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 35 before, 0 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © Glenn234-//@version=5+//@version=6strategy("MA cross strategy", shorttitle="macs", overlay=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msYes 1,000 bars in 19 msNot measured
PineTSNot testedNot testedNot measured

“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.

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/// © Glenn234//@version=5strategy("MA cross strategy", shorttitle="macs", overlay=true)// Create indicator'sshortSMA = ta.sma(close, 10)longSMA = ta.sma(close, 30)rsi = ta.rsi(close, 14)atr = ta.atr(14)// Crossover conditionslongCondition = ta.crossover(shortSMA, longSMA)shortCondition = ta.crossunder(shortSMA, longSMA)// trade conditionsif (longCondition)    stopLoss = low - atr * 2    takeProfit = high + atr * 2    strategy.entry("long", strategy.long, 100, when = rsi > 50)    strategy.exit("exit", "long", stop=stopLoss, limit=takeProfit)if (shortCondition)    stopLoss = high + atr * 2    takeProfit = low - atr * 2    strategy.entry("short", strategy.short, 100, when = rsi < 50)    strategy.exit("exit", "short", stop=stopLoss, limit=takeProfit)// Plot SMA to chartplot(shortSMA, color=color.red, title="Short SMA")plot(longSMA, color=color.green, title="Long SMA")