Indicator · Pine Script v5 · Own pane

Altcoin Analyzer [Lysergik]

by LysergikProductions· code credited to lysergik

This indicator plots the relative price of an altcoin against Bitcoin by dividing the current symbol's OHLC values by INDEX:BTCUSD data.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code103
Settings4inputs
LicenceAGPL-3.0
Last update4 years ago5 Oct 2022

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 v5 from altcoin_analyzer.pine, published under AGPL-3.0. Keep the author's credit and licence lines when you reuse it.

altcoin_analyzer.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lysergik

//@version=5
indicator("Altcoin Analyzer [Lysergik]", shorttitle='AltAnal', precision=8)

// ------------
// Inputs
bool use_candles = input.bool(false, 'Use Candles', group='Configs')
bool heikin = input.bool(true, 'Heikin Candles', group='Configs')

bool mini_display = input.bool(false, 'Mini-Display', 'Show less information in the table', group="Swag")
bool dark_mode = input.bool(true, 'Dark Mode', group='Swag')

// ------------
// Data
float btc_open = request.security("INDEX:BTCUSD",
     timeframe.period, open, barmerge.gaps_off, barmerge.lookahead_off)

float btc_high = request.security("INDEX:BTCUSD",
     timeframe.period, high, barmerge.gaps_off, barmerge.lookahead_off)

float btc_low = request.security("INDEX:BTCUSD",
     timeframe.period, low, barmerge.gaps_off, barmerge.lookahead_off)

float btc_close = request.security("INDEX:BTCUSD",
     timeframe.period, close, barmerge.gaps_off, barmerge.lookahead_off)

float o = open/btc_open
float h = high/btc_high
float l = low/btc_low
float c = close/btc_close

float btcusd_change = ( ta.highest(btc_high, 2) ) - ( ta.lowest(btc_low, 2) )
float altusd_change = ( ta.highest(high, 2) ) - ( ta.lowest(low, 2) )

color neutral_col = dark_mode ? color.white : color.black
color back_col = dark_mode ? color.black : color.white

// ------------
// Math & Logic
volatility(_change, _length, _close) =>
    lowest_roc = ta.lowest(_change, _length)
    highest_roc = ta.highest(_change, _length)
    
    volatility = ta.ema((highest_roc - lowest_roc), 2)
    percent = volatility/_close*100

btc_volatility = volatility(btcusd_change, 21, btc_close)
alt_volatility = volatility(altusd_change, 21, close)

src(_src)  => 
    Close  = not heikin ? c : math.avg(o, h, l, c)
    Open   = float(na)
    Open  := not heikin ? o  : na(Open[1]) ? (o + c) / 2 : (nz(Open[1]) + nz(Close[1])) / 2
    High   = not heikin ? h  : math.max(h, math.max(Open, Close))
    Low    = not heikin ? l   : math.min(l,  math.min(Open, Close))
    HL2    = not heikin ? math.avg(l, h)   : math.avg(High, Low) 
    HLC3   = not heikin ? math.avg(l, h, c)  : math.avg(High, Low, Close) 
    OHLC4  = not heikin ? math.avg(o, h, l, c) : math.avg(Open, High, Low, Close)
    Price  = _src == 'close' ? Close : _src == 'open' ? Open : _src == 'high' ? High : _src == 'low' ? Low : _src == 'hl2' ? HL2 : _src == 'hlc3' ? HLC3 : OHLC4  
    // PineCoders method for aligning Pine prices with chart instrument prices
    //Source = math.round(Price / syminfo.mintick) * syminfo.mintick

// ------------
// Front-End
plot(c, 'Price Line', color=use_candles ? na : neutral_col, trackprice=true)

barColor = not use_candles ? na : src('close') >= src('open') ? color.teal : color.purple
plotcandle(src('open'), src('high'), src('low'), src('close'),
     'Candles', color=barColor, wickcolor=not use_candles ? na : color.new(neutral_col, 50), bordercolor=na)

var line realLine = na
varip lineVis = false

if use_candles and
     ((lineVis == false and not barstate.isconfirmed) or
     (barstate.isrealtime and barstate.islast and not barstate.isconfirmed))
    
    line.delete(id=realLine)
    realLine := line.new(x1=bar_index[1], y1=c, x2=bar_index, y2=c, width=1, extend=extend.both)
    line.set_color(id=realLine, color=c > o ? color.purple : c < o ? color.teal : neutral_col)
    line.set_style(id=realLine, style=line.style_dashed)
    
if barstate.isconfirmed
    line.delete(id=realLine)
    lineVis := false

var table disp = table.new(position.bottom_right, 1000, 3)

if barstate.islast
    if not mini_display
        table.cell(disp, 0, 0, 'This/BTC:', text_color=neutral_col, text_size=size.auto, bgcolor=back_col)
        table.cell(disp, 1, 0, str.tostring(c, '0.00000000'), text_color=neutral_col, text_size=size.auto, bgcolor=back_col)
        
        table.cell(disp, 0, 1, 'This/USD Volatility:', text_color=neutral_col, text_size=size.auto, bgcolor=back_col)
        table.cell(disp, 1, 1, str.format('{0}%', math.round(alt_volatility, 2)), text_color=neutral_col, text_size=size.auto, bgcolor=back_col)
        
        table.cell(disp, 0, 2, 'BTC/USD Volatility', text_color=neutral_col, text_size=size.auto, bgcolor=back_col)
        table.cell(disp, 1, 2, str.format('{0}%', math.round(btc_volatility, 2)), text_color=neutral_col, text_size=size.auto, bgcolor=back_col)
    
    else if mini_display
        table.cell(disp, 0, 0, str.tostring(c, '0.00000000'), text_color=neutral_col, text_size=size.auto, bgcolor=back_col)

Overview

Altcoin Analyzer [Lysergik] displays the synthetic pair as either a simple line or custom candlesticks with an optional Heikin-Ashi calculation in a separate pane. It also measures volatility spreads between the altcoin and Bitcoin. On the live bar, a dynamic horizontal price line updates in real time.

Details

Published by

LysergikProductions on GitHub

Code credit

lysergik, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Volatility & bands, Candlestick patterns

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
Use Candlesboolfalseuse_candles
Heikin Candlesbooltrueheikin
Mini-Displayboolfalsemini_display
Dark Modebooltruedark_mode
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

Candle Pressure & Response (JMA) evaluates price action dynamics by calculating bidirectional candle pressure, upper and lower wick rejection fractions, body efficiency, and range expansion metrics relative to ATR. Each output series is smoothed using a Jurik

Indicator v6 Candlestick patternsVolatility & bands
Updated yesterday · MIT GitHub repository of Candle Pressure & Response (JMA)

GainzAlgo V2 [Alpha]

by krishnandank
4 stars

This indicator generates buy and sell signals based on engulfing candlestick patterns, a candle stability ratio relative to true range, RSI thresholds, and a multi-bar price momentum condition. It draws visual signal labels on the chart alongside suggested tak

Indicator v5 Candlestick patternsOscillators & momentum
Updated 1 year ago · None stated GitHub repository of GainzAlgo V2 [Alpha]
2 stars

This educational indicator calculates and visualizes market gap sizes in a separate pane. It computes two distinct metrics: the absolute percentage gap between the current bar open and the previous close, and the percentage gap distance between the current bar

Indicator v5 Candlestick patternsVolatility & bands
Updated 2 years ago · None stated GitHub repository of Candlesticks - Calculating Gaps

Engulf Indicator

by theomgdev
1 stars

The Engulf Indicator calculates a custom candlestick metric in a separate pane by evaluating the ratio of candle body size to total candle range, comparing it with the previous bar's body size, and normalizing the result with the Average True Range (ATR). It p

Indicator v5 Candlestick patternsVolatility & bands
Updated 2 years ago · None stated GitHub repository of Engulf Indicator

Gaps

by fiji-solutions
1 stars

The Gaps indicator measures and plots the percentage price gap between consecutive bars in a separate pane. It evaluates whether the current bar low is above the previous bar high or the current bar high is below the previous bar low, calculating the relative

Indicator v5 Candlestick patternsVolatility & bands
Updated 2 years ago · None stated GitHub repository of Gaps

Body Mass Indicator

by harryguiacorn
219 stars

The Body Mass Indicator highlights candles with exceptionally large body ranges relative to recent price movement. It calculates the absolute distance between open and close prices. When enabled, it identifies bars where the body range achieves a new high over

Indicator v5 Volatility & bandsCandlestick patterns
Updated 1 year ago · None stated GitHub repository of Body Mass Indicator

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