Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Gap Reversion Strategy

A Pine Script v5 strategy built on RSI (close, 2) and SMA (vix, 350). It has 5 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 1 commission. 15 settings; defaults include RSI-length 2, RSI Source close and Sustain Volatility Filter For X 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 Gap Reversion Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Gap Reversion Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Does Gap Reversion Strategy run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
Does Gap Reversion Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 39.
Does Gap Reversion Strategy run in Zeal Terminal?
Yes
It compiles in 17 ms and runs 1,000 bars in 39 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctRSI$1,000,000$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. The script plots nothing itself; the lines and the lower pane are its own calculations, drawn for reference. The live re-run is not offered here: the script requests CBOE:VIX 60, which this page cannot load in your browser.

Needs CBOE:VIX 60 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.

Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

One run with the author's default settings, $1,000,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.

  • Check

    Every trade uses all the equity

    default_qty_value is 100% of equity.

  • Note

    Uses an argument v6 removed

    when = on line 38, 40, 41. 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.

SettingDefaultType and rangeFeeds
Backtest Date Range
Start Timetimestamp('01 Jan 2010 06:00 +0000')timeInDateRange
End Timetimestamp('01 Jan 2099 00:00 +0000')timeInDateRange
RSI Settings
RSI-length2intRSI
RSI SourceclosesourceRSI
Volatility Filter Settings
Sustain Volatility Filter For X Bars5intVolatilityWarning
Variance Threshold500intVolatilityWarning
Use VIX Variance Filter?This will prevent new signals from entering trades when the VIX is unusually highfalseboolReversionFilter
Trade Entry/Exit Settings
RSI Long QualifierThe selected RSI / reversion indicator value must be below this input after a gap down to place a trade20float · step 5LongEntryLimit entry Long
RSI Indicator Exit ValueThe strategy will exit the long position when the Reversion Indicator crosses over this value70float · step 5close Long
Stop %99float · step 0.25PercStop
Limit Entry Price Settings
Minimum Gap % of Price.25float · min 0 · step .1GapDown PercLimit ATRLimit
Price % Entry Limit (close-gap-%)When the strategy issues a long buy signal, a limit order is generated at this % below the prior day's close price minus Gap % input1float · min 0 · step .1Limit
ATR Long Entry Limit (close-gap-%ofATR)When the strategy issues a long buy signal, a limit order is generated at this % of ATR below the prior day's close price minus Gap % input20float · min 0 · step 5Limit
Use % of ATR entry limit instead of % of price entry limit?falseboolLimit
ATR Length5intLimit

What it calculates

  • RSIRSI Source (close), RSI-length (2)RSI · line 12
  • SMAvix, 350mean · 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 datalenrsiRSI-lengthsetting · 2highhighprice dataReversionRuleRSI Long Qualifiersetting · 20ATRLimitATR Long Entry Limit (c…setting · 20PercLimitPrice % Entry Limit (cl…setting · 1StopPercInputStop %setting · 99timetimeprice dataStartTimeStart Timesetting · timestamp('01 Jan 2…EndTimeEnd Timesetting · timestamp('01 Jan 2…VolWarningLengthSustain Volatility Filt…setting · 5SquaredDifferenceThresholdVariance Thresholdsetting · 500openopenprice dataGapPercMinimum Gap % of Pricesetting · .25LongExitRSI Indicator Exit Valuesetting · 70RSIRSI→ RSImeanSMA→ meanvixvixvalueSquaredDifferenceSquaredDifferencevalueReversionFilterReversionFiltervalueLongEntryLimitLongEntryLimitvalueLimitLimitvaluePercStopPercStopvalueInDateRangeInDateRangeconditionVolatilityWarningVolatilityWarningconditionGapDownGapDownconditionentry:LongOpen Longstrategy.entryexit:Exitexit Exitstrategy.exitcancel_all:cancel_all strategy.cancel_allclose:LongClose Longstrategy.closeclose_all:close_all strategy.close_all

Order rules

OrderFires whenBy defaultLine
Open Long longReversionRule==true and ReversionFilterOn38
Exit Exit stop(InDateRange)On39
cancel_all GapDown==falseOn40
Close LongLongExitOn41
Close (not InDateRange)On43

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
  • 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

Not run on other markets: the script requests CBOE:VIX 60, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.

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
Gap Reversion Strategy this page—v5 strategy0.0%00.0%
Bull Trend Filtered StochRSI (BTFS) by SnarkyPuppyhighest rsi smav5 strategy+36.9%2121.5%
2nd Grade Strategy by cyrulesma rsi highestv4 strategyNo trades on this market
Vix FIX - StochRSI Strategy by timjsma rsi highestv5 strategy+1.0%2110.7%
Stochastic RSI by Zeal Terminalrsi highest smav5 indicatorindicator
SRJ RSI Outperformer Strategy by Sapt_Jashrsi smav5 strategy+0.6%82.4%

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.

  • 3 strategy calls use the when = argument (line 38, 40, 41). 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

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 38: when = ReversionRule==true and ReversionFilter → if block
  • Line 40: when = GapDown==false → if block
  • Line 41: when = LongExit → if block
⋯if (InDateRange)-    strategy.entry("Long", strategy.long, limit=LongEntryLimit, when = ReversionRule==true and ReversionFilter, alert_message="Buy")+    if ReversionRule==true and ReversionFilter+        strategy.entry("Long", strategy.long, limit=LongEntryLimit, alert_message="Buy")    strategy.exit("Exit", "Long", stop=PercStop, alert_message="Sell")-    strategy.cancel_all(when = GapDown==false) +    if GapDown==false+        strategy.cancel_all() -    strategy.close("Long", when = LongExit, alert_message="Sell")+    if LongExit+        strategy.close("Long", alert_message="Sell")if (not InDateRange)⋯

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-// @version=5+// @version=6// Author = TradeAutomation⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 17 msYes 1,000 bars in 39 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/// @version=5// Author = TradeAutomationstrategy(title="Gap Reversion Strategy", shorttitle="Gap Reversion Strategy", process_orders_on_close=false, overlay=true, pyramiding=0, commission_type=strategy.commission.cash_per_order, commission_value=1, slippage = 1, margin_long = 75, initial_capital = 1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)// Backtest Date Range Inputs // StartTime = input.time(defval=timestamp('01 Jan 2010 06:00 +0000'), group="Backtest Date Range", title='Start Time')EndTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), group="Backtest Date Range", title='End Time')InDateRange = time>=StartTime and time<=EndTime// Wilder's RSI //lenrsi=input.int(2, title="RSI-length", group="RSI Settings")src = input.source(close, title="RSI Source", group="RSI Settings")RSI = ta.rsi(src, lenrsi)// VIX Volatility Warning Indicator & Filter //vix = request.security("CBOE:VIX", "60", high)mean = ta.sma(vix, 350)SquaredDifference = math.pow(vix-mean, 2)VolWarningLength = input.int(5, "Sustain Volatility Filter For X Bars", group="Volatility Filter Settings")SquaredDifferenceThreshold = input.int(500, "Variance Threshold", group="Volatility Filter Settings")VolatilityWarning = ta.highest(SquaredDifference, VolWarningLength)<SquaredDifferenceThresholdEarlyWarningInput = input.bool(false, "Use VIX Variance Filter?", group="Volatility Filter Settings", tooltip="This will prevent new signals from entering trades when the VIX is unusually high")ReversionFilter = EarlyWarningInput == true ? VolatilityWarning : close>0// Long Entry Rules //ReversionRule = RSI<input.float(20, "RSI Long Qualifier", tooltip="The selected RSI / reversion indicator value must be below this input after a gap down to place a trade", group="Trade Entry/Exit Settings", step=5)GapPerc = (1-(input.float(.25, "Minimum Gap % of Price", step=.1, group="Limit Entry Price Settings", minval=0)*.01))GapDown = open<close[1]*GapPercvar float LongEntryLimit=naPercLimit = (close*GapPerc)*(1-input.float(1, "Price % Entry Limit (close-gap-%)", tooltip="When the strategy issues a long buy signal, a limit order is generated at this % below the prior day's close price minus Gap % input", step=.1, minval=0, group="Limit Entry Price Settings")*.01)ATRLimit = (close*GapPerc)-(ta.atr(input.int(5, "ATR Length"))*input.float(20, "ATR Long Entry Limit (close-gap-%ofATR)", tooltip="When the strategy issues a long buy signal, a limit order is generated at this % of ATR below the prior day's close price minus Gap % input",step=5, minval=0, group="Limit Entry Price Settings")*.01)LimitInput = input.bool(false, "Use % of ATR entry limit instead of % of price entry limit?", group="Limit Entry Price Settings")Limit = LimitInput == true ? ATRLimit : PercLimitLongEntryLimit := ReversionRule==true ? Limit : naLongExit = RSI>input.float(70, "RSI Indicator Exit Value", tooltip="The strategy will exit the long position when the Reversion Indicator crosses over this value", group="Trade Entry/Exit Settings", step=5)// Stop //StopPercInput = 1-(input.float(99, "Stop %", step=0.25, group="Trade Entry/Exit Settings")*.01)PercStop = strategy.position_avg_price*StopPercInput// Entry and Exit Functions //if (InDateRange)    strategy.entry("Long", strategy.long, limit=LongEntryLimit, when = ReversionRule==true and ReversionFilter, alert_message="Buy")    strategy.exit("Exit", "Long", stop=PercStop, alert_message="Sell")    strategy.cancel_all(when = GapDown==false)     strategy.close("Long", when = LongExit, alert_message="Sell")if (not InDateRange)    strategy.close_all()