Strategy · Pine Script v4 · Own pane

Binance Liquidations

by hasnocool

Binance Liquidations is a strategy and separate-pane indicator that estimates derivative volume activity by calculating the volume spread between Binance perps and Coinbase spot data.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code58
Settings11inputs
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

58 lines of Pine Script v4 from Binance Estimaed Liquidations indicator-strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Binance Estimaed Liquidations indicator-strategy.pine
//@version=4
strategy("Binance Liquidations", pyramiding=1, default_qty_type=strategy.cash, default_qty_value=1000, initial_capital=1000,overlay=false, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.07)
fastLen = input(title="Fast Ma lenght", type=input.integer, defval=8)
slowLen = input(title="Slow Ma lenght", type=input.integer, defval=22)
premVal = input(title="Premium Value", type=input.float, defval=2000000)
doTrades = input(title="Trades?", type=input.bool, defval=true)
onlyLong = input(title="Only long?", type=input.bool, defval=true)
smoothStrat = input(title="Smooth strat?", type=input.bool, defval=false)
diffStrat = input(title="Diff strat?", type=input.bool, defval=true)
maStrat = input(title="MA strat?", type=input.bool, defval=false)
timeRestr = input(title="Time restrictions?", type=input.bool, defval=true)
assetLiquidated = input(title="Pair", type = input.string, defval = "btcperp")
assetSpot = input(title="Pair", type = input.string, defval = "btc")
//res = input(title="resolution ", type=input.resolution, defval=timeframe.period)
coinbase = "coinbase:"+assetSpot+"usd"
binance = "binance:"+assetLiquidated
inDateRange = (time >= timestamp(syminfo.timezone, 2021,
         01, 29, 0, 0) and time<=timestamp(syminfo.timezone, 2021,
         04, 20, 0, 0)) or not timeRestr
A = security(coinbase,timeframe.period,volume)
B = security(binance,timeframe.period,volume)
premium = (B - A)
if (open < close)
    premium := 0
//plot(wma(premium,fastLen), title="CME vs. Coinbase Spread", linewidth = 3, color = color.red)
//plot(wma(premium,slowLen), title="CME vs. Coinbase Spread", linewidth = 3, color = color.green)
supersmoother(_src, _length) =>
    pi      = 2 * asin(1)
    s_a1    = exp(-sqrt(2) * pi / _length)
    s_b1    = 2 * s_a1 * cos(sqrt(2) * pi / _length)
    s_c3    = -pow(s_a1, 2)
    s_c2    = s_b1
    s_c1    = 1 - s_c2 - s_c3
    ss      = 0.0
    ss     := s_c1 * _src + s_c2 * nz(ss[1], _src[1]) + s_c3 * nz(ss[2], _src[2])
    
premiumSmooth = supersmoother(wma(premium,fastLen), fastLen*1.5)
hline(0, title="0", linewidth = 2, color = color.red, linestyle = hline.style_solid)
mainSeries = (diffStrat) ? premium : wma(premium,fastLen)
plot(mainSeries, linewidth = 2, color = color.white, style = (diffStrat) ? plot.style_histogram : plot.style_line)
series = (smoothStrat) ? premiumSmooth : na
series := (maStrat) ? wma(premium,slowLen) : na
plot(series, linewidth = 2, color = color.green)
wmaFast = wma(premium,fastLen)
WMA = wma(close, 4*24*5)
buySignal = false
sellSignal = false
if (doTrades)
    buySignal := (smoothStrat) ? crossover(premiumSmooth,premVal) : crossover(wmaFast,premVal)
    sellSignal := (smoothStrat) ? crossunder(premiumSmooth,premVal) : crossunder(wmaFast,premVal)
    buySignal := (diffStrat) ? crossover(premium,premVal) : buySignal
    sellSignal := (diffStrat) ? crossunder(premium,premVal) : sellSignal
    buySignal := (maStrat) ? crossover(wmaFast,wma(premium,slowLen)) : buySignal
    sellSignal := (maStrat) ? crossunder(wmaFast,wma(premium,slowLen)) : sellSignal
strategy.entry("long", strategy.long, when = buySignal and inDateRange and close > WMA)
strategy.entry("short", strategy.short, when = sellSignal and not onlyLong and inDateRange)
strategy.exit(id="XL TP", limit=strategy.position_avg_price * 1.01, stop=strategy.position_avg_price * 0.99)
Expand (75 lines)

Overview

Binance Liquidations applies Weighted Moving Averages and a SuperSmoother filter to the volume differential. Trades enter when the volume spread crosses a user-defined threshold while price remains above a long-term trend filter. Position exits are managed with fixed one-percent take-profit and stop-loss limits.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Volume, Moving averages

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Fast Ma lenghtint8fastLen
Slow Ma lenghtint22slowLen
Premium Valuefloat2000000premVal
Trades?booltruedoTrades
Only long?booltrueonlyLong
Smooth strat?boolfalsesmoothStrat
Diff strat?booltruediffStrat
MA strat?boolfalsemaStrat
Time restrictions?booltruetimeRestr
PairstringbtcperpassetLiquidated
PairstringbtcassetSpot
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

BTC Futures MACD

by iamrichardD
57 stars

This strategy plots a MACD oscillator in a separate pane and trades Bitcoin futures from zero-line and signal-line crosses. Optional early momentum signals, a volume filter, and a trend moving-average filter can confirm entries. It sizes positions as fixed con

Strategy v6 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of BTC Futures MACD
13 stars

This strategy plots an On-Balance Volume oscillator in a separate pane and applies a fast and a slow exponential moving average to it. It enters long or short when those averages cross, with a strategy type that can reverse, stay long only, or stay short only,

Strategy v5 VolumeMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard QN OBVOsc A002
257 stars

This overlay strategy is built for ES futures on the one-minute chart. It plots a volume-weighted moving average of price opens and standard-deviation bands at Fibonacci ratios, plus a second longer volume-weighted average from a higher-timeframe open. Call an

Strategy v5 Volatility & bandsMoving averages
Updated 6 weeks ago · None stated GitHub repository of ES Futures 1M No Repaint
218 stars

This strategy enters long when a faster moving average crosses above a slower one and short when it crosses below, unless long-only mode is on. An optional volume filter requires volume above a 20-bar average times a multiplier. Exits use a percentage stop los

Strategy v6 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of MA Cross Strategy Template
39 stars

This intraday strategy implements Mark Fisher's Opening Range Breakout (ORB) methodology tailored for index futures like ES and NQ. It calculates session opening ranges, volume z-scores, and VWAP bands to plot support, resistance, and confirmation levels on th

Strategy v6 BreakoutSessions & time Repaints
Updated 4 days ago · MIT GitHub repository of Futures Intraday Pro (ES/NQ) Strategy

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