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
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 verifiedNeither 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 verifiedNeither 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Year | 2010 | int · min 1970 | startDate |
| To Day | 31 | int · min 1 · max 31 | finishDate |
| To Month | 12 | int · min 1 · max 12 | finishDate |
| To Year | 2021 | int · min 1970 | finishDate |
| Use Correlation candles? | true | bool | haClose haOpen haHigh haLow |
| Symbol (no label in the script) | CRYPTOCAP:TOTAL | symbol | haClose haOpen haHigh haLow |
| Length (no label in the script) | 50 | int | vrsi |
| Over Sold (no label in the script) | 51 | int | long |
| Over Bought (no label in the script) | 49 | int | short |
| Source | haClose | string · options ["haClose", "haOpen", "haHigh", "haLow"] | price |
| Length Moving average | 8 | int · min 1 | ma |
| Take Profit long (no label in the script) | 1.0 | float · step 0.005 | exit short_tp/sl |
| Stop Loss long (no label in the script) | 0.1 | float · step 0.005 | exit short_tp/sl |
| Take Profit short (no label in the script) | 0.05 | float · step 0.005 | exit short_tp/sl |
| Stop Loss short (no label in the script) | 0.03 | float · step 0.005 | exit short_tp/sl |
What it calculates
- SMA (
sma,ta.smain v5)src, Length Moving average (8)ma · line 30 - RSI (
rsi,ta.rsiin 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longcrossover(vrsi, overSold) and time_cond and price > ma | On | 38 |
| Open short short | shortcrossunder(vrsi, overBought) and time_cond and price < ma | On | 39 |
| Exit short_tp/sl stop and limit | every bar | On | 40 |
| Exit short_tp/sl stop and limit | every bar | On | 41 |
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.
- 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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Crypto swing correlation RSI and SMA this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| SRJ RSI Outperformer Strategy by Sapt_Jash | rsi sma | v5 strategy | +0.6% | 8 | 2.4% |
| RSI SMA Crossover Strategy by reees | rsi sma | v5 strategy | +39.8% | 42 | 30.8% |
| Short In Downtrend Below MA100 (Coinrule) by Coinrule | sma rsi | v4 strategy | −34.5% | 99 | 45.4% |
| Simple RSI and SMA Long and Short (by Coinrule) by Coinrule | rsi sma | v5 strategy | −3.0% | 2 | 17.7% |
| Maximized Moving Average Crossing (by Coinrule) by Coinrule | sma rsi | v4 strategy | −6.6% | 9 | 13.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | With a workaround 1,000 bars in 47 ms | Not measured |
| PineTS | No 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')