Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

REVERSALS

A Pine Script v4 strategy built on SMA (close, 200). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 2 settings; defaults include Stop Loss .95 and How Many Bars 5.

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 REVERSALS 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 REVERSALS do on BTCUSDT 1D with default settings?
+3.27%
From 26 Jan 2024 to 21 Oct 2026, over 29 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can REVERSALS 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 REVERSALS use a stop loss?
Yes
strategy.exit sets a stop on line 23.
Does REVERSALS run in Zeal Terminal?
Yes
It compiles in 6 ms and runs 1,000 bars in 38 ms, in the browser.

BTCUSDT · 1D · default settings

  • MarketFilter
  • StopLossLine
  • 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 (2)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$103,275$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 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 19) so the engine trades the way the script says.
Net profit
+3.27%
$3,273.31
Buy and hold
+102.5%
same period
Closed trades
29
16 won · 13 lost
Profitable
55.2%
of closed trades
Profit factor
1.06
gross profit ÷ gross loss
Max drawdown
18.34%
−$21,583.30

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

    sma(close, 200) ignores the settings line 15

    Line 15 hard-codes 200 where line 12 uses “How Many Bars”. Changing those settings moves one band but not this one.

    sma(close, 200)sma(close, HowManyBars)
  • Check

    No commission

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

  • Note

    2 settings have no label

    In the settings dialog StopLoss (line 9), HowManyBars (line 10) show 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 an argument v6 removed

    when = on line 19. 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.
  • 1 strategy call uses the when = argument (line 19). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 1: //@version=4 → //@version=5
  • Line 12: sma → ta.sma
  • Line 15: sma → ta.sma
  • Line 16: sma → ta.sma
  • Line 19: strategy.entry(…, true) → strategy.entry(…, strategy.long)
-//  @version=4+//  @version=5//  © HermanBrummer⋯///     EXITS-if  close > sma(high,HowManyBars)[1]+if  close > ta.sma(high,HowManyBars)[1]    strategy.close_all()///     ENTRIES-MarketFilter    = sma(close, 200)+MarketFilter    = ta.sma(close, 200)-F1              = close < sma(low,HowManyBars)[1]+F1              = close < ta.sma(low,HowManyBars)[1]F2              = close > MarketFilterplot(MarketFilter, "MarketFilter", color.yellow)-strategy.entry("Long", true, 1, when=F1 and F2)+strategy.entry("Long", strategy.long, 1, when=F1 and F2)///     STOP LOSS⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 9: input() → input.float()
  • Line 10: input() → input.int()
  • Line 19: when = F1 and F2 → if block
⋯strategy("REVERSALS", overlay=true)-StopLoss    = input(.95, step=0.01)+StopLoss    = input.float(.95, step=0.01)-HowManyBars = input( 5 )+HowManyBars = input.int( 5 )///     EXITS⋯plot(MarketFilter, "MarketFilter", color.yellow)-strategy.entry("Long", strategy.long, 1, when=F1 and F2)+if F1 and F2+    strategy.entry("Long", strategy.long, 1)///     STOP LOSS⋯

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: 29 before, 28 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.

-//  @version=5+//  @version=6//  © HermanBrummer⋯

Settings

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

SettingDefaultType and rangeFeeds
Stop Loss (no label in the script).95float · step 0.01StopLossLine
How Many Bars (no label in the script)5intF1 close_all line 12

What it calculates

  • SMA (sma, ta.sma in v5)close, 200MarketFilter · 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.

closecloseprice dataStopLossStop Losssetting · .95lowlowprice dataHowManyBarsHow Many Barssetting · 5highhighprice dataMarketFilterSMA→ MarketFilterStopLossLineStopLossLinevalueF1F1conditionF2F2conditionclose_all:close_all strategy.close_allentry:LongOpen Longstrategy.entryexit:Exitexit Exitstrategy.exitplot:18MarketFilterplotplot:22StopLossLineplot

Order rules

OrderFires whenBy defaultLine
Close close > sma(high,HowManyBars)[1]On13
Open Long longF1 and F2On19
Exit Exit stopevery barOn23

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+3.3%+102.5%2955%1.0618.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+9.7%+5.5%3361%2.203.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.5%+9.8%2744%0.831.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.3%+8.4%3269%1.830.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.1%+16.7%3732%0.640.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%3057%0.980.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.2%+148.3%3549%1.300.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.1%+17.1%2662%1.860.0%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 market1867%$15,979.70
Sideways market1136%−$12,706.40
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?

26.9%

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

0%31%
All 29 trades
SideEntryExitBarsP&L
long24 Oct 2024 66,668.6029 Oct 2024 69,962.205$3,293.56
long3 Nov 2024 69,374.707 Nov 2024 75,572.004$6,197.25
long26 Nov 2024 93,010.0030 Nov 2024 97,460.004$4,449.99
long19 Dec 2024 100,204.0020 Dec 2024 95,193.801−$5,010.21
long21 Dec 2024 97,805.4023 Dec 2024 92,915.202−$4,890.28
long24 Dec 2024 94,881.5026 Dec 2024 99,429.602$4,548.14
long28 Dec 2024 94,299.003 Jan 2025 96,984.806$2,685.76
long9 Jan 2025 95,060.6013 Jan 2025 90,307.604−$4,753.04
long28 Jan 2025 102,083.0031 Jan 2025 104,723.003$2,640.11
long2 Feb 2025 100,636.003 Feb 2025 95,603.901−$5,031.79
long5 Feb 2025 97,763.1021 Feb 2025 98,305.0016$541.87
long25 Feb 2025 91,552.9026 Feb 2025 86,975.201−$4,577.65
long27 Feb 2025 84,250.1028 Feb 2025 80,037.601−$4,212.51
long1 Mar 2025 84,349.903 Mar 2025 94,270.002$9,920.04
long5 May 2025 94,277.607 May 2025 96,834.002$2,556.41
long30 May 2025 105,590.0010 Jun 2025 110,263.0011$4,673.27
long13 Jun 2025 105,672.0022 Jun 2025 100,388.009−$5,283.59
long23 Jun 2025 100,964.0024 Jun 2025 105,334.001$4,370.07
long2 Jul 2025 105,681.003 Jul 2025 108,850.001$3,168.46
long1 Aug 2025 115,764.008 Aug 2025 117,472.007$1,707.95
long16 Aug 2025 117,342.0023 Aug 2025 116,936.007−$406.04
long26 Aug 2025 110,112.003 Sep 2025 111,240.008$1,128.03
long23 Sep 2025 112,651.0029 Sep 2025 112,164.006−$487.03
long10 Oct 2025 121,662.0011 Oct 2025 112,774.001−$8,887.92
long12 Oct 2025 110,644.0017 Oct 2025 105,112.005−$5,532.22
long30 Oct 2025 110,021.004 Nov 2025 104,520.005−$5,501.07
long2 Sep 2026 77,439.004 Sep 2026 81,270.402$3,831.36
long9 Sep 2026 78,455.8019 Sep 2026 80,883.9010$2,428.06
long8 Oct 2026 83,321.8021 Oct 2026 83,028.1013−$293.67

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
REVERSALS this page—v4 strategy+3.3%2918.3%
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 6 msWith a workaround 1,000 bars in 38 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 19) 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//  © HermanBrummer//  This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0///  BUYS    WHEN THE CLOSE IS SMALLER THAN THE LOW OF 5 DAYS AGO//  SELLS   WHEN THE CLOSE IS HIGHER THEN THE HIGH OF 5 DAYS AGO//  USES A 200 MOVING AVERGE AS A FILTER, AND DOESN'T TAKE TRADES IF THE MARKET IS BELOW IT'S 200 MA//  USES A 5% STOP LOSS FROM ENTRIESstrategy("REVERSALS", overlay=true)StopLoss    = input(.95, step=0.01)HowManyBars = input( 5 )///     EXITSif  close > sma(high,HowManyBars)[1]    strategy.close_all()///     ENTRIESMarketFilter    = sma(close, 200)F1              = close < sma(low,HowManyBars)[1]F2              = close > MarketFilterplot(MarketFilter, "MarketFilter", color.yellow)strategy.entry("Long", true, 1, when=F1 and F2)///     STOP LOSSStopLossLine    = strategy.position_avg_price * StopLossplot(StopLossLine, "StopLossLine", #FF0000)strategy.exit("Exit", stop=StopLossLine)