Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Crypto swing correlation RSI and SMA

A Pine Script v4 strategy built on SMA (src, 8) and RSI (price, 50). 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 commits 100% of equity and pays 0.03% commission. 17 settings; defaults include From Day 1, From Month 1 and From Year 2010.

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 Crypto swing correlation RSI and SMA repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did Crypto swing correlation RSI and SMA 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.
Can Crypto swing correlation RSI and SMA be converted to Pine Script v5?
Not tested
The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
Does Crypto swing correlation RSI and SMA use a stop loss?
Yes
strategy.exit sets a stop on line 40, 41.
Does Crypto swing correlation RSI and SMA run in Zeal Terminal?
Yes
It compiles in 11 ms and runs 1,000 bars in 47 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct5149RSI$1$2Equity from $1
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. Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 38, 39) 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. The live re-run is not offered here: the script requests CRYPTOCAP:TOTAL D, which this page cannot load in your browser.

Needs CRYPTOCAP:TOTAL D data, not available: not a Binance spot market 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 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

    8 settings have no label

    In the settings dialog symbol (line 18), length (line 23), overSold (line 24), overBought (line 25), takeProfit_long (line 34), stopLoss_long (line 35), takeProfit_short (line 36), stopLoss_short (line 37) show an empty name. The labels on this page come from the variable names.

  • Note

    Uses an argument v6 removed

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

v4 → v5

Not verified

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

  • Line 3: //@version=4 → //@version=5
  • Line 18: input(type = input.symbol) → input.symbol()
  • Line 19: security → request.security
  • Line 20: security → request.security
  • Line 21: security → request.security
  • Line 22: security → request.security
6 more edits
  • Line 30: sma → ta.sma
  • Line 31: rsi → ta.rsi
  • Line 32: crossover → ta.crossover
  • Line 33: crossunder → ta.crossunder
  • Line 38: strategy.entry(…, 1) → strategy.entry(…, strategy.long)
  • Line 39: strategy.entry(…, 0) → strategy.entry(…, strategy.short)
⋯// © exlux99-//@version=4+//@version=5strategy(title = "Crypto swing correlation", overlay = true,  pyramiding=1,initial_capital = 1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)⋯useCorrelation    = input(true, title="Use Correlation candles?")-symbol = input("CRYPTOCAP:TOTAL", type=input.symbol)+symbol = input.symbol("CRYPTOCAP:TOTAL")-haClose = useCorrelation ? security(symbol, timeframe.period, close) : close+haClose = useCorrelation ? request.security(symbol, timeframe.period, close) : close-haOpen  = useCorrelation ? security(symbol, timeframe.period, open) : open+haOpen  = useCorrelation ? request.security(symbol, timeframe.period, open) : open-haHigh  = useCorrelation ? security(symbol, timeframe.period, high) : high+haHigh  = useCorrelation ? request.security(symbol, timeframe.period, high) : high-haLow   = useCorrelation ? security(symbol, timeframe.period, low) : low+haLow   = useCorrelation ? request.security(symbol, timeframe.period, low) : lowlength = input( 50 )⋯src = price-ma = sma(src, len)+ma = ta.sma(src, len)-vrsi = rsi(price, length)+vrsi = ta.rsi(price, length)-long = crossover(vrsi, overSold) and time_cond and price > ma+long = ta.crossover(vrsi, overSold) and time_cond and price > ma-short = crossunder(vrsi, overBought) and time_cond and price < ma+short = ta.crossunder(vrsi, overBought) and time_cond and price < matakeProfit_long=input(1.0, step=0.005)⋯stopLoss_short=input(0.03, step=0.005)-strategy.entry("long",1,when=long)+strategy.entry("long",strategy.long,when=long)-strategy.entry("short",0,when=short)+strategy.entry("short",strategy.short,when=short)strategy.exit("short_tp/sl", "long", profit=close * takeProfit_long / syminfo.mintick, loss=close * stopLoss_long / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')⋯

Clean v5

Not verified

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

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 11: input() → input.int()
  • Line 12: input() → input.int()
  • Line 13: input() → input.int()
12 more edits
  • Line 17: input() → input.bool()
  • Line 23: input() → input.int()
  • Line 24: input() → input.int()
  • Line 25: input() → input.int()
  • Line 26: input() → input.string()
  • Line 28: input() → input.int()
  • Line 34: input() → input.float()
  • Line 35: input() → input.float()
  • Line 36: input() → input.float()
  • Line 37: input() → input.float()
  • Line 38: when = long → if block
  • Line 39: when = short → if block
⋯//time-fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-fromYear = input(defval = 2010, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2010, title = "From Year", minval = 1970) //monday and session // To Date Inputs-toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)+toDay = input.int(defval = 31, title = "To Day", minval = 1, maxval = 31)-toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)+toMonth = input.int(defval = 12, title = "To Month", minval = 1, maxval = 12)-toYear = input(defval = 2021, title = "To Year", minval = 1970)+toYear = input.int(defval = 2021, title = "To Year", minval = 1970)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)⋯time_cond = time >= startDate and time <= finishDate-useCorrelation    = input(true, title="Use Correlation candles?")+useCorrelation    = input.bool(true, title="Use Correlation candles?")symbol = input.symbol("CRYPTOCAP:TOTAL")⋯haLow   = useCorrelation ? request.security(symbol, timeframe.period, low) : low-length = input( 50 )+length = input.int( 50 )-overSold = input( 51 )+overSold = input.int( 51 )-overBought = input( 49 )+overBought = input.int( 49 )-s = input(title="Source", defval="haClose", options=["haClose", "haOpen", "haHigh", "haLow"])+s = input.string(title="Source", defval="haClose", options=["haClose", "haOpen", "haHigh", "haLow"])price = s == "haClose" ? haClose: s == "haOpen" ? haOpen : s == "haHigh" ? haHigh : s == "haLow" ? haLow : na-len = input(8, "Length Moving average", minval=1)+len = input.int(8, "Length Moving average", minval=1)src = price⋯short = ta.crossunder(vrsi, overBought) and time_cond and price < ma-takeProfit_long=input(1.0, step=0.005)+takeProfit_long=input.float(1.0, step=0.005)-stopLoss_long=input(0.1, step=0.005)+stopLoss_long=input.float(0.1, step=0.005)-takeProfit_short=input(0.05, step=0.005)+takeProfit_short=input.float(0.05, step=0.005)-stopLoss_short=input(0.03, step=0.005)+stopLoss_short=input.float(0.03, step=0.005)-strategy.entry("long",strategy.long,when=long)+if long+    strategy.entry("long",strategy.long)-strategy.entry("short",strategy.short,when=short)+if short+    strategy.entry("short",strategy.short)strategy.exit("short_tp/sl", "long", profit=close * takeProfit_long / syminfo.mintick, loss=close * stopLoss_long / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')⋯

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.

⋯// © exlux99-//@version=5+//@version=6strategy(title = "Crypto swing correlation", overlay = true,  pyramiding=1,initial_capital = 1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)⋯

Settings

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

SettingDefaultType and rangeFeeds
From Day1int · min 1 · max 31startDate
From Month1int · min 1 · max 12startDate
From Year2010int · min 1970startDate
To Day31int · min 1 · max 31finishDate
To Month12int · min 1 · max 12finishDate
To Year2021int · min 1970finishDate
Use Correlation candles?trueboolhaClose haOpen haHigh haLow
Symbol (no label in the script)CRYPTOCAP:TOTALsymbolhaClose haOpen haHigh haLow
Length (no label in the script)50intvrsi
Over Sold (no label in the script)51intlong
Over Bought (no label in the script)49intshort
SourcehaClosestring · options ["haClose", "haOpen", "haHigh", "haLow"]price
Length Moving average8int · min 1ma
Take Profit long (no label in the script)1.0float · step 0.005exit short_tp/sl
Stop Loss long (no label in the script)0.1float · step 0.005exit short_tp/sl
Take Profit short (no label in the script)0.05float · step 0.005exit short_tp/sl
Stop Loss short (no label in the script)0.03float · step 0.005exit short_tp/sl

What it calculates

  • SMA (sma, ta.sma in v5)src, Length Moving average (8)ma · line 30
  • RSI (rsi, ta.rsi in v5)price, Length (50)vrsi · line 31

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.

lenLength Moving averagesetting · 8lengthLengthsetting · 50fromYearFrom Yearsetting · 2010fromMonthFrom Monthsetting · 1fromDayFrom Daysetting · 1toYearTo Yearsetting · 2021toMonthTo Monthsetting · 12toDayTo Daysetting · 31closecloseprice datasymbolSymbolsetting · CRYPTOCAP:TOTALopenopenprice datahighhighprice datalowlowprice datasSourcesetting · haCloseoverSoldOver Soldsetting · 51overBoughtOver Boughtsetting · 49timetimeprice datamaSMA→ mavrsiRSI→ vrsistartDatestartDatevaluefinishDatefinishDatevaluehaClosehaClosevaluehaOpenhaOpenvaluehaHighhaHighvaluehaLowhaLowvaluepricepricevaluesrcsrcvaluelonglongconditionshortshortconditiontime_condtime_condconditionentry:longOpen longstrategy.entryentry:shortOpen shortstrategy.entryexit:short_tp/slexit short_tp/slstrategy.exit

Order rules

OrderFires whenBy defaultLine
Open long longlongcrossover(vrsi, overSold) and time_cond and price > maOn38
Open short shortshortcrossunder(vrsi, overBought) and time_cond and price < maOn39
Exit short_tp/sl stop and limitevery barOn40
Exit short_tp/sl stop and limitevery barOn41

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 data4 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 CRYPTOCAP:TOTAL D, and that data is not available here (not a Binance spot market). 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
Crypto swing correlation RSI and SMA this page—v4 strategy0.0%00.0%
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%
Maximized Moving Average Crossing (by Coinrule) by Coinrulesma rsiv4 strategy−6.6%913.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 11 msWith a workaround 1,000 bars in 47 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as 1, 0 as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 38, 39) 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/// © exlux99//@version=4strategy(title = "Crypto swing correlation", overlay = true,  pyramiding=1,initial_capital = 1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)//timefromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2010, title = "From Year", minval = 1970) //monday and session // To Date InputstoDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)toMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12)toYear = input(defval = 2021, title = "To Year", minval = 1970)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)time_cond = time >= startDate and time <= finishDateuseCorrelation    = input(true, title="Use Correlation candles?")symbol = input("CRYPTOCAP:TOTAL", type=input.symbol)haClose = useCorrelation ? security(symbol, timeframe.period, close) : closehaOpen  = useCorrelation ? security(symbol, timeframe.period, open) : openhaHigh  = useCorrelation ? security(symbol, timeframe.period, high) : highhaLow   = useCorrelation ? security(symbol, timeframe.period, low) : lowlength = input( 50 )overSold = input( 51 )overBought = input( 49 )s = input(title="Source", defval="haClose", options=["haClose", "haOpen", "haHigh", "haLow"])price = s == "haClose" ? haClose: s == "haOpen" ? haOpen : s == "haHigh" ? haHigh : s == "haLow" ? haLow : nalen = input(8, "Length Moving average", minval=1)src = pricema = sma(src, len)vrsi = rsi(price, length)long = crossover(vrsi, overSold) and time_cond and price > mashort = crossunder(vrsi, overBought) and time_cond and price < matakeProfit_long=input(1.0, step=0.005)stopLoss_long=input(0.1, step=0.005)takeProfit_short=input(0.05, step=0.005)stopLoss_short=input(0.03, step=0.005)strategy.entry("long",1,when=long)strategy.entry("short",0,when=short)strategy.exit("short_tp/sl", "long", profit=close * takeProfit_long / syminfo.mintick, loss=close * stopLoss_long / syminfo.mintick, comment='LONG EXIT',  alert_message = 'closeshort')strategy.exit("short_tp/sl", "short", profit=close * takeProfit_short / syminfo.mintick, loss=close * stopLoss_short / syminfo.mintick, comment='SHORT EXIT',  alert_message = 'closeshort')