Indicator · Pine Script v5 · Own pane

Hash Ribbons

by theonetrade

Calculates Bitcoin hash rate moving averages to identify miner capitulation and recovery phases.

View on GitHub

Repaints

GitHub stars34on the repository
Pine versionv5runs as is
Lines of code122
Settings7inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

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

122 lines of Pine Script v5 from assets/indicator/bit-exact/hash_ribbons_kT7jIvqv.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

hash_ribbons_kT7jIvqv.pine
//@version=5
indicator('Hash Ribbons (Capriole Investments)', overlay=false)

// NOTES

// The "Spring" is the confirmed Miner capitulation period:
// - The 1st "gray" circle is the start of Capitulation (1 month Hash Rate crosses UNDER 2 month Hash Rate)
// - Last "green" circle is the end of Capitulation (1 month Hash Rate crosses OVER 2 month Hash Rate)
// - The "greener" the spring gets (up until blue) represents Hash Rate recovery (it is increasing)
// - The "blue" circle is the first instance of positive momentum following recovery of Hash Rate (1m HR > 2m HR). This is historically a rewarding place to buy with limited downside.

// INPUTS

type = input.string('Ribbons', options=['Ribbons', 'Oscillator'], title='Plot Type')
len_s = input(30, 'Hash Rate Short SMA (days).')
len_l = input(60, 'Hash Rate Long SMA (days).')
signals = input(true, 'Plot Signals')
plot_halvings = input(true, 'Plot Halvings')
raw = input(false, 'Plot Raw Hash Rate')
source = input.string('INTOTHEBLOCK:BTC_HASHRATE', options=['QUANDL:BCHAIN/HRATE', 'INTOTHEBLOCK:BTC_HASHRATE'], title='Source Hash Rate')

// HASH RATE MA

// HR on TV only has "yesterday's" value --> use "lookahead_on" when running live (on current bar), to pull forward yesterdays data
live_HR_raw = request.security(source, 'D', close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
live_HR_short = request.security(source, 'D', ta.sma(close, len_s), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
live_HR_long = request.security(source, 'D', ta.sma(close, len_l), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

hist_HR_raw = request.security(source, 'D', close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
hist_HR_short = request.security(source, 'D', ta.sma(close, len_s), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
hist_HR_long = request.security(source, 'D', ta.sma(close, len_l), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)

daily_s10 = request.security(syminfo.tickerid, 'D', ta.sma(close, 10), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
daily_s20 = request.security(syminfo.tickerid, 'D', ta.sma(close, 20), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)


// DAILY TIMEFRAME MGMT

is_newbar(res) =>
    t = time(res)  // res calculated below \/
    ta.change(t) != 0 ? true : false

// Check how many bars are in our upper (otf) timeframe
since_new_bar = ta.barssince(is_newbar('D'))  //1-360 for minutes, D = Daily, W = Weekly, M = Monthly
D_total_bars = int(na)
D_total_bars := since_new_bar == 0 ? since_new_bar[1] : D_total_bars[1]  // calculates the total number of current time frame bars in the OTF 

// INDICATORS

HR_short = float(na)
HR_long = float(na)
HR_raw = float(na)
s10 = float(na)
s20 = float(na)

HR_short := barstate.isrealtime ? live_HR_short : hist_HR_short
HR_long := barstate.isrealtime ? live_HR_long : hist_HR_long
HR_raw := barstate.isrealtime ? live_HR_raw : hist_HR_raw

s10 := barstate.isrealtime ? since_new_bar == D_total_bars ? daily_s10 : s10[1] : daily_s10
s20 := barstate.isrealtime ? since_new_bar == D_total_bars ? daily_s20 : s20[1] : daily_s20

capitulation = ta.crossunder(HR_short, HR_long)
miner_capitulation = HR_short < HR_long
recovering = HR_short > HR_short[1] and HR_short > HR_short[2] and HR_short > HR_short[3] and miner_capitulation
recovered = ta.crossover(HR_short, HR_long)

// HASH BOTTOM + PA SIGNAL

buy = false
buy := ta.crossover(s10, s20) and ta.barssince(recovered) < ta.barssince(ta.crossunder(s10, s20)) and ta.barssince(recovered) < ta.barssince(capitulation) or s10 > s20 and ta.crossover(HR_short, HR_long)

buy_plot = buy


// OSCILLATOR

delta = HR_short - HR_long
diff = delta / HR_short * 100

// PLOT - DEFAULT

plot(raw ? HR_raw : na, color=color.new(color.green, 0), linewidth=1, style=plot.style_line, title='HR Raw')
p1 = plot(type == 'Ribbons' ? HR_long : na, color=color.new(color.gray, 0), linewidth=2, style=plot.style_line, title='HR SMA Long')
p2 = plot(type == 'Ribbons' ? HR_short : na, color=HR_short < HR_long ? color.red : color.lime, linewidth=2, style=plot.style_line, title='HR SMA Short')
fill(p1, p2, color=HR_short < HR_long ? color.new(color.red,30) : na)

// PLOT - OSCILLATOR

plot(type == 'Oscillator' ? diff : na, style=plot.style_columns, color=diff < 0 ? color.red : color.blue, title='Oscillator')

// PLOT - SIGNALS

plotshape(signals ? capitulation : na, style=shape.circle, location=location.top, color=color.new(color.gray, 50), size=size.normal, text='Capitulation', textcolor=color.new(color.black, 50), title='Capitulation')
plotshape(signals ? miner_capitulation : na, style=shape.circle, location=location.top, color=color.new(color.green, 90), size=size.normal, title='Miner Capitulation')
plotshape(signals ? recovering : na, style=shape.circle, location=location.top, color=color.new(color.green, 50), size=size.normal, title='Recovering')
plotshape(signals ? recovered : na, style=shape.circle, location=location.top, color=color.new(color.lime, 0), size=size.normal, textcolor=color.new(color.white, 0), title='Recovered')
plotshape(signals ? buy_plot : na, style=shape.circle, location=location.top, color=color.new(color.blue, 0), size=size.normal, text='Buy', textcolor=color.new(color.blue, 0), title='Buy')

// Sourcing
var table_source = table(na)
table_source := table.new(position=position.bottom_left, columns=1, rows=1, bgcolor=color.white, border_width=1)
table.cell(table_source, 0, 0, text='Source: Capriole Investments Limited', bgcolor=color.white, text_color=color.black, width=20, height=7, text_size=size.normal, text_halign=text.align_left)

// HALVINGS

halving_1 = timestamp(2012, 11, 28, 0, 0)
halving_2 = timestamp(2016, 7, 9, 0, 0)
halving_3 = timestamp(2020, 5, 12, 0, 0)  // projected! https://www.bitcoinclock.com/
band = 2
h1_range = time >= halving_1 - band * 24 * 60 * 60 * 1000 and time <= halving_1 + band * 24 * 60 * 60 * 1000  //adds 3 day either side for chart visibility
h2_range = time >= halving_2 - band * 24 * 60 * 60 * 1000 and time <= halving_2 + band * 24 * 60 * 60 * 1000  //adds 3 day either side for chart visibility
h3_range = time >= halving_3 - band * 24 * 60 * 60 * 1000 and time <= halving_3 + band * 24 * 60 * 60 * 1000  //adds 3 day either side for chart visibility
bgcolor(h1_range and plot_halvings ? color.new(color.red,20) : na)
bgcolor(h2_range and plot_halvings ? color.new(color.red,20) : na)
bgcolor(h3_range and plot_halvings ? color.new(color.red,20) : na)

//ALERTS

alertcondition(capitulation, title='Alert - Capitulation')
alertcondition(recovered, title='Alert - Recovered')
alertcondition(buy and not buy[1], title='Alert - Buy')

Overview

Hash Ribbons plots ribbons or an oscillator in a separate pane along with buy signals and halving markers based on hash rate crossovers. Main settings adjust the short and long moving average lengths, plot types, and data sources. It uses lookahead data for live bar calculations.

Details

Published by

theonetrade on GitHub

Draws

Separate pane below the chart

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Plot TypestringRibbonstype
Hash Rate Short SMA (days).int30len_s
Hash Rate Long SMA (days).int60len_l
Plot Signalsbooltruesignals
Plot Halvingsbooltrueplot_halvings
Plot Raw Hash Rateboolfalseraw
Source Hash RatestringINTOTHEBLOCK:BTC_HASHRATEsource
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

MACD Breakout

by jerryinyang
5 stars

MACD Breakout builds a higher-timeframe MACD from preset fast and slow lengths using SMA or EMA, and marks support and resistance zones from histogram sensitivity. Optional filters require zero-line agreement, higher-timeframe direction, and linear-regression

Indicator v4 Oscillators & momentumMoving averages
Updated 2 years ago · None stated GitHub repository of MACD Breakout

Cipher B

by diehardyearone
3 stars

Cipher B is a multi-indicator plotting WaveTrend oscillator lines and signals alongside Stochastic RSI, MFI area with color bars, and buy sell marks. It draws all elements in a separate pane. WaveTrend calculates using SMMA and EMA on source like ohlc4 with ad

Indicator v6 Oscillators & momentumMoving averages
Updated 1 year ago · None stated GitHub repository of Cipher B

Custom Oscillator

by danielbodnar
2 stars

This reference script provides practical Pine Script v6 code examples for creating custom indicators. It includes a smoothed Relative Strength Index oscillator plotted with overbought and oversold background zones, a multi-timeframe moving average overlay with

Indicator v6 Oscillators & momentumMoving averages
Updated 12 days ago · MIT GitHub repository of Custom Oscillator

Uabmacd

by avatar-lavventura
2 stars

The script plots a WaveTrend oscillator in a separate pane, calculating TCI as an EMA of a normalized price deviation and its 4-bar SMA. It displays overbought and oversold levels with colored circles for WT1-WT2 crossovers and bar coloring on crossover bars.

Indicator v4 Oscillators & momentumMoving averages
Updated 8 months ago · None stated GitHub repository of Uabmacd

Composite Market Bias

by mrme000m
1 stars

Composite Market Bias is a separate-pane indicator that scores bullish and bearish conditions from RSI, fast versus slow EMA, MACD histogram, Bollinger Band position, and price versus a 50-period EMA. It plots the resulting bias score with RSI, EMA trend, MACD

Indicator v5 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of Composite Market Bias

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers