BTC - Hotness Index
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dakixr

//@version=4

study("BTC - Hotness Index")

// Pi Cycle Top Indicator
/////////////////////////////////////////

D_111SMA = security(syminfo.tickerid, "1D",sma(close,111))
D_350SMA = security(syminfo.tickerid, "1D",sma(close,350)*2)

pi_indicator = (D_111SMA / D_350SMA)

pi_plot =  pi_indicator[1] < 1 and pi_indicator[0] >= 1? 1 : 0
pi_plot_buy =  pi_indicator[1] > 0.35 and pi_indicator[0] <= 0.35? 1 : 0


// Horizontal Lines
/////////////////////////////////////////
hline(1, "Sell Zone", color=color.rgb(255, 255, 255, 75))
hline(0.35, "Buy Zone", color=color.rgb(255, 255, 255, 75))

// Ploting
/////////////////////////////////////////

plot(pi_plot, color = pi_plot == 1? color.rgb(255, 59, 59) : #476b6b, style = plot.style_histogram)
plot(pi_plot_buy, color = pi_plot_buy == 1? color.rgb(82, 255, 59) : #476b6b, style = plot.style_histogram)
plot(pi_indicator)