Strategy · Pine Script v4 · On the chart

BTC Candle Correlation Strategy

by hasnocool· code credited to exlux99

This strategy constructs a synthetic Bitcoin price feed by averaging open, high, low, and close data across seven cryptocurrency exchanges.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code91
Settings9inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

91 lines of Pine Script v4 from BTC Candle Correlation Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

BTC Candle Correlation Strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © exlux99
//@version=4
strategy(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 average
src_c = close
src1_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 = high
src1_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 = low
src1_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 = open
src1_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 variables
candle_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 -2
h=pow(candle_high,2) / 2
l=pow(candle_low,2) / 2
o=pow(candle_open,2) /2
c=pow(candle_close,2) /2
x=(h+l+o+c) / 4
y= sqrt(x)
source = y
useTrueRange = false
length = input(9, minval=1)
mult = input(0.9, step=0.1)
ma = sma(source, length)
range = useTrueRange ? tr : candle_high - candle_low
rangema = sma(range, length)
upper = ma + rangema * mult
lower = ma - rangema * mult
crossUpper = crossover(source, upper)
crossLower = crossunder(source, lower)
bprice = 0.0
bprice := crossUpper ? candle_high: nz(bprice[1])
sprice = 0.0
sprice := crossLower ? candle_low  : nz(sprice[1])
crossBcond = false
crossBcond := crossUpper ? true
     : na(crossBcond[1]) ? false : crossBcond[1]
crossScond = false
crossScond := 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 Inputs
toDay = 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)
Expand (114 lines)

Overview

BTC Candle Correlation Strategy derives a composite price value using quadratic averaging and plots a volatility envelope around its simple moving average. Trade entries trigger when the composite price crosses the upper or lower channel bands. User settings control the smoothing length, channel multiplier, long-only toggle, and backtest date range. The strategy displays directly on the price chart and includes no stop-loss rules.

Details

Published by

hasnocool on GitHub

Code credit

exlux99, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Volatility & bands, Breakout

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
lengthint9length
multfloat0.9mult
longOnlybooltruelongOnly
From Dayint1fromDay
From Monthint1fromMonth
From Yearint2000fromYear
To Dayint31toDay
To Monthint12toMonth
To Yearint2021toYear
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
218 stars

This strategy detects price breakouts above rolling highest highs or below lowest lows over a customizable lookback period. It includes optional volume spike and ATR volatility threshold filters, along with bar confirmation rules. Positions are taken upon conf

Strategy v6 BreakoutVolatility & bands
Updated 3 months ago · None stated GitHub repository of Breakout Strategy Template

Bollinger Breakout

by hackingthemarkets
189 stars

This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w

Strategy v4 Volatility & bandsBreakout
Updated 3 years ago · None stated GitHub repository of Bollinger Breakout

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统

Bollinger bands examples

by tradingstrategy-ai
53 stars

This strategy plots exponential-moving-average Bollinger bands on the price chart and calculates RSI. It opens a long position when close crosses above the upper band while RSI is at or above a threshold, the date filter allows trading, and no position is open

Strategy v5 Volatility & bandsOscillators & momentum
Updated 3 years ago · None stated GitHub repository of Bollinger bands examples

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers