HASHRATE and MINER REVENUE
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Jomy

//@version=5
indicator('HASHRATE and MINER REVENUE', overlay=false)
hrocs = input.float(-3.6, 'hash rate of change to short', step=.2)

leverage = input.float(1, 'leverage', step=.1)
enableshorts = input(true, 'enable shorting?')


live_HR_raw = request.security('QUANDL:BCHAIN/HRATE', 'D', close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

hist_HR_raw = request.security('QUANDL:BCHAIN/HRATE', 'D', close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)

live_MR_raw = request.security('QUANDL:BCHAIN/MIREV', 'D', close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

hist_MR_raw = request.security('QUANDL:BCHAIN/MIREV', 'D', close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
HR_raw = float(na)
MR_raw = float(na)

HR_raw := barstate.isrealtime ? live_HR_raw : hist_HR_raw
MR_raw := barstate.isrealtime ? live_MR_raw : hist_MR_raw
//plot(HR_raw)

filt = HR_raw
filt := 0.193463 * (HR_raw + HR_raw[1]) / 2 + 1.217833 * nz(filt[1]) + -0.411296 * nz(filt[2])
filt2 = MR_raw
filt2 := 0.193463 * (MR_raw + MR_raw[1]) / 2 + 1.217833 * nz(filt2[1]) + -0.411296 * nz(filt2[2])
filt3 = (filt + filt2) / 2

plot(filt3,color=color.blue,linewidth=2)

buy = filt3 > filt3[1]
sell = filt3 < filt3[1]

hashroc = (filt3 / filt3[1] - 1) * 100

plotshape(true, style=shape.square, location=location.bottom, size=size.tiny, color=buy ? color.rgb(0, 255, 0, 20) : sell and hashroc < hrocs ? color.rgb(255, 0, 0, 20) : color.rgb(0, 0, 0, 90))
bgcolor(buy ? color.rgb(0, 255, 0, 80) : sell and hashroc < hrocs ? color.rgb(255, 0, 0, 80) : na)



