Pine Script v4 · Strategy
BTC Candle Correlation Strategy
A Pine Script v4 strategy built on SMA (source, 9), Crossover (source, upper) and Crossunder (source, lower). It has 6 order rules, 3 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1% commission. 9 settings; defaults include Length 9, Mult 0.9 and From Day 1.
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 BTC Candle Correlation 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 BTC Candle Correlation 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.
- Can BTC Candle Correlation Strategy 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 BTC Candle Correlation Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does BTC Candle Correlation Strategy run in Zeal Terminal?
- Yes
- It compiles in 24 ms and runs 1,000 bars in 102 ms, in the browser.
BTCUSDT · 1D · default settings
- SMA
- SMA
- Crossover
- Crossunder
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BITFINEX:BTCUSD D data, not available: not a Binance spot market Needs POLONIEX:BTCUSDT D data, not available: not a Binance spot market Needs BITSTAMP:BTCUSD D data, not available: not a Binance spot market Needs COINBASE:BTCUSD D data, not available: not a Binance spot market Needs BITMEX:XBTUSD D data, not available: not a Binance spot market Needs KRAKEN:XBTUSD 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,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
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
3 settings have no label
In the settings dialog length (line 44), mult (line 45), longOnly (line 65) 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.
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, avg → math.avg, pow → math.pow, sqrt → math.sqrt, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.
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 7: security → request.security
- Line 7: security → request.security
- Line 8: security → request.security
- Line 8: security → request.security
- Line 9: security → request.security
38 more edits
- Line 9: security → request.security
- Line 10: security → request.security
- Line 12: security → request.security
- Line 12: security → request.security
- Line 13: security → request.security
- Line 13: security → request.security
- Line 14: security → request.security
- Line 14: security → request.security
- Line 15: security → request.security
- Line 17: security → request.security
- Line 17: security → request.security
- Line 18: security → request.security
- Line 18: security → request.security
- Line 19: security → request.security
- Line 19: security → request.security
- Line 20: security → request.security
- Line 22: security → request.security
- Line 22: security → request.security
- Line 23: security → request.security
- Line 23: security → request.security
- Line 24: security → request.security
- Line 24: security → request.security
- Line 25: security → request.security
- Line 27: avg → math.avg
- Line 28: avg → math.avg
- Line 29: avg → math.avg
- Line 30: avg → math.avg
- Line 36: pow → math.pow
- Line 37: pow → math.pow
- Line 38: pow → math.pow
- Line 39: pow → math.pow
- Line 41: sqrt → math.sqrt
- Line 46: sma → ta.sma
- Line 47: range is reserved in v5: renamed range_
- Line 47: tr → ta.tr
- Line 48: sma → ta.sma
- Line 51: crossover → ta.crossover
- Line 52: crossunder → ta.crossunder
⋯// © exlux99-//@version=4+//@version=5strategy(title="BTC Candle Correlation Strategy", overlay=true, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, pyramiding=1 )⋯src_c = close-src1_c = security("BITFINEX:BTCUSD", timeframe.period, src_c), src2_c = security("POLONIEX:BTCUSDT", timeframe.period, src_c),+src1_c = request.security("BITFINEX:BTCUSD", timeframe.period, src_c), src2_c = request.security("POLONIEX:BTCUSDT", timeframe.period, src_c),-src3_c = security("BITSTAMP:BTCUSD", timeframe.period, src_c), src4_c = security("COINBASE:BTCUSD", timeframe.period, src_c),+src3_c = request.security("BITSTAMP:BTCUSD", timeframe.period, src_c), src4_c = request.security("COINBASE:BTCUSD", timeframe.period, src_c),-src5_c = security("BITMEX:XBTUSD", timeframe.period, src_c), src6_c = security("KRAKEN:XBTUSD", timeframe.period, src_c),+src5_c = request.security("BITMEX:XBTUSD", timeframe.period, src_c), src6_c = request.security("KRAKEN:XBTUSD", timeframe.period, src_c),-src7_c = security("BINANCE:BTCUSDT", timeframe.period, src_c)+src7_c = request.security("BINANCE:BTCUSDT", timeframe.period, src_c)src_h = high-src1_h = security("BITFINEX:BTCUSD", timeframe.period, src_h), src2_h = security("POLONIEX:BTCUSDT", timeframe.period, src_h),+src1_h = request.security("BITFINEX:BTCUSD", timeframe.period, src_h), src2_h = request.security("POLONIEX:BTCUSDT", timeframe.period, src_h),-src3_h = security("BITSTAMP:BTCUSD", timeframe.period, src_h), src4_h = security("COINBASE:BTCUSD", timeframe.period, src_h),+src3_h = request.security("BITSTAMP:BTCUSD", timeframe.period, src_h), src4_h = request.security("COINBASE:BTCUSD", timeframe.period, src_h),-src5_h = security("BITMEX:XBTUSD", timeframe.period, src_h), src6_h = security("KRAKEN:XBTUSD", timeframe.period, src_h),+src5_h = request.security("BITMEX:XBTUSD", timeframe.period, src_h), src6_h = request.security("KRAKEN:XBTUSD", timeframe.period, src_h),-src7_h = security("BINANCE:BTCUSDT", timeframe.period, src_h)+src7_h = request.security("BINANCE:BTCUSDT", timeframe.period, src_h)src_l = low-src1_l = security("BITFINEX:BTCUSD", timeframe.period, src_l), src2_l = security("POLONIEX:BTCUSDT", timeframe.period, src_l),+src1_l = request.security("BITFINEX:BTCUSD", timeframe.period, src_l), src2_l = request.security("POLONIEX:BTCUSDT", timeframe.period, src_l),-src3_l = security("BITSTAMP:BTCUSD", timeframe.period, src_l), src4_l = security("COINBASE:BTCUSD", timeframe.period, src_l),+src3_l = request.security("BITSTAMP:BTCUSD", timeframe.period, src_l), src4_l = request.security("COINBASE:BTCUSD", timeframe.period, src_l),-src5_l = security("BITMEX:XBTUSD", timeframe.period, src_l), src6_l = security("KRAKEN:XBTUSD", timeframe.period, src_l), +src5_l = request.security("BITMEX:XBTUSD", timeframe.period, src_l), src6_l = request.security("KRAKEN:XBTUSD", timeframe.period, src_l), -src7_l = security("BINANCE:BTCUSDT", timeframe.period, src_l)+src7_l = request.security("BINANCE:BTCUSDT", timeframe.period, src_l)src_o = open-src1_o = security("BITFINEX:BTCUSD", timeframe.period, src_o), src2_o = security("POLONIEX:BTCUSDT", timeframe.period, src_o),+src1_o = request.security("BITFINEX:BTCUSD", timeframe.period, src_o), src2_o = request.security("POLONIEX:BTCUSDT", timeframe.period, src_o),-src3_o = security("BITSTAMP:BTCUSD", timeframe.period, src_o), src4_o = security("COINBASE:BTCUSD", timeframe.period, src_o),+src3_o = request.security("BITSTAMP:BTCUSD", timeframe.period, src_o), src4_o = request.security("COINBASE:BTCUSD", timeframe.period, src_o),-src5_o = security("BITMEX:XBTUSD", timeframe.period, src_o), src6_o = security("KRAKEN:XBTUSD", timeframe.period, src_o),+src5_o = request.security("BITMEX:XBTUSD", timeframe.period, src_o), src6_o = request.security("KRAKEN:XBTUSD", timeframe.period, src_o),-src7_o = security("BINANCE:BTCUSDT", timeframe.period, src_o)+src7_o = request.security("BINANCE:BTCUSDT", timeframe.period, src_o)//declaring variables-candle_open = avg(src1_o, src2_o, src3_o, src4_o, src5_o, src6_o, src7_o)+candle_open = math.avg(src1_o, src2_o, src3_o, src4_o, src5_o, src6_o, src7_o)-candle_high = avg(src1_h, src2_h, src3_h, src4_h, src5_h, src6_h, src7_h)+candle_high = math.avg(src1_h, src2_h, src3_h, src4_h, src5_h, src6_h, src7_h)-candle_low = avg(src1_l, src2_l, src3_l, src4_l, src5_l, src6_l, src7_l)+candle_low = math.avg(src1_l, src2_l, src3_l, src4_l, src5_l, src6_l, src7_l)-candle_close = avg(src1_c, src2_c, src3_c, src4_c, src5_c, src6_c, src7_c)+candle_close = math.avg(src1_c, src2_c, src3_c, src4_c, src5_c, src6_c, src7_c)//plots⋯// high^2 / 2 - low^2 -2-h=pow(candle_high,2) / 2+h=math.pow(candle_high,2) / 2-l=pow(candle_low,2) / 2+l=math.pow(candle_low,2) / 2-o=pow(candle_open,2) /2+o=math.pow(candle_open,2) /2-c=pow(candle_close,2) /2+c=math.pow(candle_close,2) /2x=(h+l+o+c) / 4-y= sqrt(x)+y= math.sqrt(x)source = y⋯mult = input(0.9, step=0.1)-ma = sma(source, length)+ma = ta.sma(source, length)-range = useTrueRange ? tr : candle_high - candle_low+range_ = useTrueRange ? ta.tr : candle_high - candle_low-rangema = sma(range, length)+rangema = ta.sma(range_, length)upper = ma + rangema * multlower = ma - rangema * mult-crossUpper = crossover(source, upper)+crossUpper = ta.crossover(source, upper)-crossLower = crossunder(source, lower)+crossLower = ta.crossunder(source, lower)bprice = 0.0⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 44: input() → input.int()
- Line 45: input() → input.float()
- Line 65: input() → input.bool()
- Line 66: input() → input.int()
- Line 67: input() → input.int()
- Line 68: input() → input.int()
3 more edits
- Line 71: input() → input.int()
- Line 72: input() → input.int()
- Line 73: input() → input.int()
⋯useTrueRange = false-length = input(9, minval=1)+length = input.int(9, minval=1)-mult = input(0.9, step=0.1)+mult = input.float(0.9, step=0.1)ma = ta.sma(source, length)⋯cancelScond = crossScond and (source > ma or candle_low <= sprice )-longOnly = input(true)+longOnly = input.bool(true)-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 = 2000, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2000, 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)⋯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="BTC Candle Correlation Strategy", overlay=true, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, pyramiding=1 )⋯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 |
|---|---|---|---|
| Length (no label in the script) | 9 | int · min 1 | ma rangema |
| Mult (no label in the script) | 0.9 | float · step 0.1 | upper lower |
| Long Only (no label in the script) | true | bool | line 77 line 86 |
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Year | 2000 | 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 |
What it calculates
- SMA (
sma,ta.smain v5)source, Length (9)ma · line 46 - SMA (
sma,ta.smain v5)range, Length (9)rangema · line 48 - Crossover (
crossover,ta.crossoverin v5)source, uppercrossUpper · line 51 - Crossunder (
crossunder,ta.crossunderin v5)source, lowercrossLower · line 52
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 |
|---|---|---|---|
| cancel long | (crossLower) | On | 79 |
| Open long long | (crossUpper) | On | 81 |
| cancel short | (cancelScond) | On | 83 |
| Open short short | (crossLower) | On | 85 |
| Close long | (crossLower) | On | 88 |
| Open long long | (crossUpper and candle_close > candle_open) | On | 90 |
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 data28 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 BITFINEX:BTCUSD D, POLONIEX:BTCUSDT D, BITSTAMP:BTCUSD D, COINBASE:BTCUSD D, BITMEX:XBTUSD D, KRAKEN:XBTUSD D, and that data is not available here (not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; not a Binance spot market; 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 |
|---|---|---|---|---|---|
| BTC Candle Correlation Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 24 ms | With a workaround 1,000 bars in 102 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
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="BTC Candle Correlation Strategy", overlay=true, initial_capital = 1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, pyramiding=1 )//sources for averagesrc_c = closesrc1_c = security("BITFINEX:BTCUSD", timeframe.period, src_c), src2_c = security("POLONIEX:BTCUSDT", timeframe.period, src_c),src3_c = security("BITSTAMP:BTCUSD", timeframe.period, src_c), src4_c = security("COINBASE:BTCUSD", timeframe.period, src_c),src5_c = security("BITMEX:XBTUSD", timeframe.period, src_c), src6_c = security("KRAKEN:XBTUSD", timeframe.period, src_c),src7_c = security("BINANCE:BTCUSDT", timeframe.period, src_c)src_h = highsrc1_h = security("BITFINEX:BTCUSD", timeframe.period, src_h), src2_h = security("POLONIEX:BTCUSDT", timeframe.period, src_h),src3_h = security("BITSTAMP:BTCUSD", timeframe.period, src_h), src4_h = security("COINBASE:BTCUSD", timeframe.period, src_h),src5_h = security("BITMEX:XBTUSD", timeframe.period, src_h), src6_h = security("KRAKEN:XBTUSD", timeframe.period, src_h),src7_h = security("BINANCE:BTCUSDT", timeframe.period, src_h)src_l = lowsrc1_l = security("BITFINEX:BTCUSD", timeframe.period, src_l), src2_l = security("POLONIEX:BTCUSDT", timeframe.period, src_l),src3_l = security("BITSTAMP:BTCUSD", timeframe.period, src_l), src4_l = security("COINBASE:BTCUSD", timeframe.period, src_l),src5_l = security("BITMEX:XBTUSD", timeframe.period, src_l), src6_l = security("KRAKEN:XBTUSD", timeframe.period, src_l), src7_l = security("BINANCE:BTCUSDT", timeframe.period, src_l)src_o = opensrc1_o = security("BITFINEX:BTCUSD", timeframe.period, src_o), src2_o = security("POLONIEX:BTCUSDT", timeframe.period, src_o),src3_o = security("BITSTAMP:BTCUSD", timeframe.period, src_o), src4_o = security("COINBASE:BTCUSD", timeframe.period, src_o),src5_o = security("BITMEX:XBTUSD", timeframe.period, src_o), src6_o = security("KRAKEN:XBTUSD", timeframe.period, src_o),src7_o = security("BINANCE:BTCUSDT", timeframe.period, src_o)//declaring variablescandle_open = avg(src1_o, src2_o, src3_o, src4_o, src5_o, src6_o, src7_o)candle_high = avg(src1_h, src2_h, src3_h, src4_h, src5_h, src6_h, src7_h)candle_low = avg(src1_l, src2_l, src3_l, src4_l, src5_l, src6_l, src7_l)candle_close = avg(src1_c, src2_c, src3_c, src4_c, src5_c, src6_c, src7_c)//plots//plotcandle(candle_open, candle_high, candle_low, candle_close, title = "Average BTC candles", color = open < close ? color.green : color.red, wickcolor = color.white) //////////////////////////////////////////////////////////// high^2 / 2 - low^2 -2h=pow(candle_high,2) / 2l=pow(candle_low,2) / 2o=pow(candle_open,2) /2c=pow(candle_close,2) /2x=(h+l+o+c) / 4y= sqrt(x)source = yuseTrueRange = falselength = input(9, minval=1)mult = input(0.9, step=0.1)ma = sma(source, length)range = useTrueRange ? tr : candle_high - candle_lowrangema = sma(range, length)upper = ma + rangema * multlower = ma - rangema * multcrossUpper = crossover(source, upper)crossLower = crossunder(source, lower)bprice = 0.0bprice := crossUpper ? candle_high: nz(bprice[1])sprice = 0.0sprice := crossLower ? candle_low : nz(sprice[1])crossBcond = falsecrossBcond := crossUpper ? true : na(crossBcond[1]) ? false : crossBcond[1]crossScond = falsecrossScond := crossLower ? true : na(crossScond[1]) ? false : crossScond[1]cancelBcond = crossBcond and (source < ma or candle_high >= bprice )cancelScond = crossScond and (source > ma or candle_low <= sprice )longOnly = input(true)fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2000, 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 <= finishDate if(longOnly==false and time_cond) if (crossLower) strategy.cancel("long") if (crossUpper) strategy.entry("long", strategy.long) if (cancelScond) strategy.cancel("short") if (crossLower) strategy.entry("short", strategy.short)if(longOnly and time_cond) if (crossLower) strategy.close("long") if (crossUpper and candle_close > candle_open) strategy.entry("long", strategy.long)