Indicator · Pine Script v6 · On the chart

Liquidation Levels

by mrgunkin

This indicator calculates estimated long and short liquidation prices from a manually entered base price and five leverage settings.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code103
Settings23inputs
LicenceMIT
Last update1 year ago6 Mar 2025

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

103 lines of Pine Script v6 from Liquidation Levels/Liquidation Levels.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Liquidation Levels.pine
//
// @author Mrgunkin [GitHub Profile](https://github.com/mrgunkin)
//
//@version=6
indicator("Liquidation Levels", shorttitle="Liq Levels", overlay=true)

// Ввод базовой цены вручную
inputPrice = input.float(50000, title="Manual Base Price") 

// Входные параметры
i_nonlinear = input(true, title="Nonlinear Contract (e.g. COIN-M)")
i_maintmargin = input.float(0.05, title="Maintenance Margin above Liquidation")
maint_margin = 1 - i_maintmargin

// Плечи
i_x1 = input.float(5, title="Level #1")
i_x2 = input.float(10, title="Level #2")
i_x3 = input.float(20, title="Level #3")
i_x4 = input.float(50, title="Level #4")
i_x5 = input.float(100, title="Level #5")

// Параметры отображения
i_show_longs = input(true, title="Show long levels")
i_show_shorts = input(true, title="Show short levels")
i_show_x1 = input(true, title="Show Level 1 Labels")
i_show_x2 = input(true, title="Show Level 2 Labels")
i_show_x3 = input(true, title="Show Level 3 Labels")
i_show_x4 = input(true, title="Show Level 4 Labels")
i_show_x5 = input(true, title="Show Level 5 Labels")

i_showlast = input.int(1, title="Only Show Last X Bars (0 = all)")
i_offset = input.int(0, title="Projection offset")
i_label_offset = input.int(5, title="Level Label Offset")

// Цвета уровней
c_x1 = input.color(color.aqua, title="Level 1 Colour")
c_x2 = input.color(color.lime, title="Level 2 Colour")
c_x3 = input.color(color.yellow, title="Level 3 Colour")
c_x4 = input.color(color.orange, title="Level 4 Colour")
c_x5 = input.color(color.red, title="Level 5 Colour")
c_base = color.gray // Цвет для Base Price

// Функция расчета ликвидационных уровней
liqLevel(_price, _x) =>
    _xlong = i_nonlinear ? _x + 1 : _x
    _xshort = i_nonlinear ? _x - 1 : _x
    _liq_long = _price * (1 - (1 / _xlong * maint_margin))
    _liq_short = _price * (1 + (1 / _xshort * maint_margin))
    [_liq_long, _liq_short]

// Расчет уровней
[x1_long, x1_short] = liqLevel(inputPrice, i_x1)
[x2_long, x2_short] = liqLevel(inputPrice, i_x2)
[x3_long, x3_short] = liqLevel(inputPrice, i_x3)
[x4_long, x4_short] = liqLevel(inputPrice, i_x4)
[x5_long, x5_short] = liqLevel(inputPrice, i_x5)

// Отображение уровней
plot(inputPrice, title="Base Price", color=c_base, offset=i_offset, show_last=i_showlast) 
plot(x1_long, title="L1 Long", color=c_x1, offset=i_offset, show_last=i_showlast)
plot(x2_long, title="L2 Long", color=c_x2, offset=i_offset, show_last=i_showlast)
plot(x3_long, title="L3 Long", color=c_x3, offset=i_offset, show_last=i_showlast)
plot(x4_long, title="L4 Long", color=c_x4, offset=i_offset, show_last=i_showlast)
plot(x5_long, title="L5 Long", color=c_x5, offset=i_offset, show_last=i_showlast)

plot(x1_short, title="L1 Short", color=c_x1, offset=i_offset, show_last=i_showlast)
plot(x2_short, title="L2 Short", color=c_x2, offset=i_offset, show_last=i_showlast)
plot(x3_short, title="L3 Short", color=c_x3, offset=i_offset, show_last=i_showlast)
plot(x4_short, title="L4 Short", color=c_x4, offset=i_offset, show_last=i_showlast)
plot(x5_short, title="L5 Short", color=c_x5, offset=i_offset, show_last=i_showlast)

// Функция отображения уровней на графике
f_print(_y, _txt, _c) =>
    t = time + ((i_offset + i_label_offset) * timeframe.multiplier * 60 * 1000)
    label.new(t, _y, _txt, xloc.bar_time, yloc.price, color.white, label.style_none, _c, size.small)

// Отображение подписей
if barstate.islast
    f_print(inputPrice, str.format("Base Price: {0}", inputPrice), c_base)
    
    if i_show_longs
        if i_show_x1
            f_print(x1_long, str.format("+{0}x: {1}", i_x1, x1_long), c_x1)
        if i_show_x2
            f_print(x2_long, str.format("+{0}x: {1}", i_x2, x2_long), c_x2)
        if i_show_x3
            f_print(x3_long, str.format("+{0}x: {1}", i_x3, x3_long), c_x3)
        if i_show_x4
            f_print(x4_long, str.format("+{0}x: {1}", i_x4, x4_long), c_x4)
        if i_show_x5
            f_print(x5_long, str.format("+{0}x: {1}", i_x5, x5_long), c_x5)
            
    if i_show_shorts
        if i_show_x1
            f_print(x1_short, str.format("-{0}x: {1}", i_x1, x1_short), c_x1)
        if i_show_x2
            f_print(x2_short, str.format("-{0}x: {1}", i_x2, x2_short), c_x2)
        if i_show_x3
            f_print(x3_short, str.format("-{0}x: {1}", i_x3, x3_short), c_x3)
        if i_show_x4
            f_print(x4_short, str.format("-{0}x: {1}", i_x4, x4_short), c_x4)
        if i_show_x5
            f_print(x5_short, str.format("-{0}x: {1}", i_x5, x5_short), c_x5)

Overview

A maintenance-margin factor shifts each level, and a nonlinear option changes the leverage used for inverse-style contracts. It plots the base price plus up to five long and five short levels on the price chart, with separate colors and optional labels. Users can hide either side, limit drawing to the last bars, and offset the lines and labels. It does not issue entries, exits, or position management.

Details

Published by

mrgunkin on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance

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.

Settings

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

SettingTypeDefaultVariable
Manual Base Pricefloat50000inputPrice
Nonlinear Contract (e.g. COIN-M)booltruei_nonlinear
Maintenance Margin above Liquidationfloat0.05i_maintmargin
Level #1float5i_x1
Level #2float10i_x2
Level #3float20i_x3
Level #4float50i_x4
Level #5float100i_x5
Show long levelsbooltruei_show_longs
Show short levelsbooltruei_show_shorts
Show Level 1 Labelsbooltruei_show_x1
Show Level 2 Labelsbooltruei_show_x2
Show all 23 settings
SettingTypeDefaultVariable
Show Level 3 Labelsbooltruei_show_x3
Show Level 4 Labelsbooltruei_show_x4
Show Level 5 Labelsbooltruei_show_x5
Only Show Last X Bars (0 = all)int1i_showlast
Projection offsetint0i_offset
Level Label Offsetint5i_label_offset
Level 1 Colourcolorcolor.aquac_x1
Level 2 Colourcolorcolor.limec_x2
Level 3 Colourcolorcolor.yellowc_x3
Level 4 Colourcolorcolor.orangec_x4
Level 5 Colourcolorcolor.redc_x5
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

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers