Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

ma 20 high-low

A Pine Script v4 strategy built on SMA (high, 20), Crossover (close, smaH) and Crossunder (close, 0.99*smaH). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. 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 20 high-low repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 14 of 14 trades.
How did ma 20 high-low do on BTCUSDT 1D with default settings?
+2,790.13%
From 26 Jan 2024 to 21 Oct 2026, over 59 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can ma 20 high-low 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 ma 20 high-low use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does ma 20 high-low run in Zeal Terminal?
Yes
It compiles in 8 ms and runs 1,000 bars in 21 ms, in the browser.

BTCUSDT · 1D · default settings

  • smaHigh
  • smaLow
  • 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$2,595,430$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.
Net profit
+2,790.13%
$2,790,130.00
Buy and hold
+102.5%
same period
Closed trades
59
20 won · 39 lost
Profitable
33.9%
of closed trades
Profit factor
1.22
gross profit ÷ gross loss
Max drawdown
2,731.63%
−$3,788,720.00

One run with the author's default settings, $100,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 stop loss

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

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

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.
  • 4 strategy calls use the when = argument (line 22, 23, 25, 26). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 59 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: sma → ta.sma
  • Line 7: sma → ta.sma
  • Line 12: crossover → ta.crossover
  • Line 13: crossunder → ta.crossunder
  • Line 14: crossunder → ta.crossunder
  • Line 15: crossover → ta.crossover
⋯// © AlanAntony-//@version=4+//@version=5strategy("ma 20 high-low",overlay=true)//compute the indicators-smaH = sma(high, 20)+smaH = ta.sma(high, 20)-smaL = sma(low, 20)+smaL = ta.sma(low, 20)//plot the indicators⋯//trading logic-enterlong = crossover(close,smaH) //positive ema crossover+enterlong = ta.crossover(close,smaH) //positive ema crossover-exitlong = crossunder(close,0.99*smaH)  //exiting long+exitlong = ta.crossunder(close,0.99*smaH)  //exiting long-entershort = crossunder(close,smaL) //negative EMA Crossover+entershort = ta.crossunder(close,smaL) //negative EMA Crossover-exitshort = crossover(close,1.01*smaH) //exiting shorts+exitshort = ta.crossover(close,1.01*smaH) //exiting shortsnotintrade = strategy.position_size<=0⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 22: when = enterlong → if block
  • Line 23: when = entershort → if block
  • Line 25: when = exitlong → if block
  • Line 26: when = exitshort → if block
⋯if time >= start-    strategy.entry( "long", strategy.long,100, when = enterlong)+    if enterlong+        strategy.entry( "long", strategy.long,100)-    strategy.entry( "short", strategy.short,100, when = entershort) +    if entershort+        strategy.entry( "short", strategy.short,100)     -    strategy.close("long", when = exitlong)+    if exitlong+        strategy.close("long")-    strategy.close("short", when = exitshort)+    if exitshort+        strategy.close("short")//if time >= end⋯

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: 59 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.

⋯// © AlanAntony-//@version=5+//@version=6strategy("ma 20 high-low",overlay=true)⋯

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

  • SMA (sma, ta.sma in v5)high, 20smaH · line 6
  • SMA (sma, ta.sma in v5)low, 20smaL · line 7
  • Crossover (crossover, ta.crossover in v5)close, smaHenterlong · line 12
  • Crossunder (crossunder, ta.crossunder in v5)close, 0.99*smaHexitlong · line 13
  • Crossunder (crossunder, ta.crossunder in v5)close, smaLentershort · line 14
  • Crossover (crossover, ta.crossover in v5)close, 1.01*smaHexitshort · line 15

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.

highhighprice datalowlowprice dataclosecloseprice datasmaHSMA→ smaHsmaLSMA→ smaLenterlongCrossover→ enterlongexitlongCrossunder→ exitlongentershortCrossunder→ entershortexitshortCrossover→ exitshortnotintradenotintradeconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryclose:longClose longstrategy.closeclose:shortClose shortstrategy.closeplot:9smaHighplotplot:10smaLowplotbgcolor:17bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open long longenterlongOn22
Open short shortentershortOn23
Close longexitlongOn25
Close shortexitshortOn26

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.

14/14trades 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+2,790.1%+102.5%5934%1.222,731.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+315.6%+5.5%5028%1.07458.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+71.9%+9.8%6136%1.1098.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−62.4%+8.4%6221%0.7377.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+7.5%+16.7%7037%1.1910.8%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+2.6%+21.5%5431%1.402.1%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−13.7%+148.3%6832%0.8969.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+12.9%+17.1%5141%1.478.5%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 market2330%−$1,939,750.00
Sideways market2339%$726,892.00
Falling market1331%$4,002,990.00

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

How bad could the drawdown be?

26,764.2%

The 95th percentile of the worst drawdown when the same 59 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 127.1% to 26,764.2%; the tick is what actually happened, 2,528.7%. Order luck alone moves it this much.

0%30,779%
All 59 trades
SideEntryExitBarsP&L
long18 Mar 2024 68,393.5019 Mar 2024 67,610.001−$78,347.00
short20 Mar 2024 61,937.4026 Mar 2024 69,880.006−$794,259.00
long26 Mar 2024 69,880.003 Apr 2024 65,464.008−$441,601.00
short3 Apr 2024 65,464.009 Apr 2024 71,620.006−$615,601.00
long9 Apr 2024 71,620.0010 Apr 2024 69,146.001−$247,400.00
long11 Apr 2024 70,631.1013 Apr 2024 67,116.502−$351,456.00
short13 Apr 2024 67,116.5016 May 2024 66,206.5033$91,001.00
long16 May 2024 66,206.501 Jun 2024 67,540.0016$133,350.00
long5 Jun 2024 70,537.808 Jun 2024 69,355.603−$118,223.00
short12 Jun 2024 67,314.2015 Jul 2024 60,797.9033$651,632.00
long15 Jul 2024 60,797.901 Aug 2024 64,628.0017$383,010.00
short3 Aug 2024 61,498.3022 Aug 2024 61,156.0019$34,231.00
long22 Aug 2024 61,156.0028 Aug 2024 59,415.006−$174,103.00
short29 Aug 2024 59,034.9014 Sep 2024 60,498.0016−$146,309.00
long14 Sep 2024 60,498.0017 Sep 2024 58,214.003−$228,400.00
long18 Sep 2024 60,314.002 Oct 2024 60,804.9014$49,093.00
short2 Oct 2024 60,804.9015 Oct 2024 66,084.0013−$527,908.00
long15 Oct 2024 66,084.004 Nov 2024 68,776.0020$269,199.00
long7 Nov 2024 75,572.0010 Dec 2024 97,276.5033$2,170,450.00
long12 Dec 2024 101,125.0019 Dec 2024 100,204.007−$92,099.00
short23 Dec 2024 95,186.307 Jan 2025 102,236.0015−$704,932.00
long7 Jan 2025 102,236.008 Jan 2025 96,954.601−$528,100.00
short10 Jan 2025 92,552.5016 Jan 2025 100,497.006−$794,486.00
long16 Jan 2025 100,497.0029 Jan 2025 101,336.0013$83,817.00
long30 Jan 2025 103,733.001 Feb 2025 102,430.002−$130,369.00
short3 Feb 2025 97,700.6025 Mar 2025 87,498.2050$1,020,240.00
long25 Mar 2025 87,498.2029 Mar 2025 84,424.404−$307,378.00
short31 Mar 2025 82,390.0013 Apr 2025 85,276.9013−$288,691.00
long13 Apr 2025 85,276.9014 Apr 2025 83,760.001−$151,691.00
long18 Apr 2025 84,947.9030 May 2025 105,590.0042$2,064,180.00
short31 May 2025 103,985.0010 Jun 2025 110,263.0010−$627,755.00
long10 Jun 2025 110,263.0013 Jun 2025 105,672.003−$459,128.00
short21 Jun 2025 103,298.0026 Jun 2025 107,341.005−$404,261.00
long26 Jun 2025 107,341.002 Jul 2025 105,681.006−$165,946.00
long3 Jul 2025 108,850.0030 Jul 2025 117,951.0027$910,116.00
short1 Aug 2025 115,764.0011 Aug 2025 119,294.0010−$353,020.00
long11 Aug 2025 119,294.0016 Aug 2025 117,342.005−$195,223.00
short20 Aug 2025 112,873.0011 Sep 2025 113,960.0022−$108,705.00
long11 Sep 2025 113,960.0023 Sep 2025 112,651.0012−$130,901.00
short23 Sep 2025 112,651.002 Oct 2025 118,595.009−$594,400.00
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$582,050.00
short11 Oct 2025 112,774.004 Dec 2025 93,429.9054$1,934,450.00
long4 Dec 2025 93,429.906 Dec 2025 89,330.002−$409,991.00
long10 Dec 2025 92,678.8013 Dec 2025 90,268.403−$241,038.00
short15 Dec 2025 88,172.203 Jan 2026 89,995.1019−$182,298.00
long3 Jan 2026 89,995.1021 Jan 2026 88,427.7018−$156,748.00
short21 Jan 2026 88,427.703 Mar 2026 68,830.1041$1,959,760.00
long3 Mar 2026 68,830.107 Mar 2026 68,114.004−$71,604.00
long11 Mar 2026 69,948.6020 Mar 2026 69,930.009−$1,863.00
short23 Mar 2026 67,859.008 Apr 2026 71,924.2016−$406,522.00
long8 Apr 2026 71,924.2030 Apr 2026 75,780.0022$385,578.00
long2 May 2026 78,231.1016 May 2026 79,113.2014$88,207.00
short17 May 2026 78,148.106 Jul 2026 63,650.0050$1,449,800.00
long6 Jul 2026 63,650.0025 Jul 2026 64,140.0019$48,999.00
long27 Jul 2026 65,400.0028 Jul 2026 63,755.901−$164,414.00
short1 Aug 2026 62,887.9018 Aug 2026 64,532.1017−$164,423.00
long18 Aug 2026 64,532.109 Sep 2026 78,455.8022$1,392,370.00
short11 Sep 2026 76,568.7019 Sep 2026 80,883.908−$431,513.00
long19 Sep 2026 80,883.908 Oct 2026 83,321.8019$243,795.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 20 high-low this page—v4 strategy+2,790.1%592,731.6%
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 8 msYes 1,000 bars in 21 msNot measured
PineTSNo v5 and v6 only—Not 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. 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/// © AlanAntony//@version=4strategy("ma 20 high-low",overlay=true)//compute the indicatorssmaH = sma(high, 20)smaL = sma(low, 20)//plot the indicatorsplot(smaH,title="smaHigh", color=color.green, linewidth=2)plot(smaL,title="smaLow", color=color.red, linewidth=2)//trading logicenterlong = crossover(close,smaH) //positive ema crossoverexitlong = crossunder(close,0.99*smaH)  //exiting longentershort = crossunder(close,smaL) //negative EMA Crossoverexitshort = crossover(close,1.01*smaH) //exiting shortsnotintrade = strategy.position_size<=0bgcolor(notintrade ? color.red:color.green)//execution logicstart = timestamp(2015,6,1,0,0)//end = timestamp(2022,6,1,0,0)if time >= start    strategy.entry( "long", strategy.long,100, when = enterlong)    strategy.entry( "short", strategy.short,100, when = entershort)         strategy.close("long", when = exitlong)    strategy.close("short", when = exitshort)//if time >= end   // strategy.close_all()