TARVIS Labs - Bitcoin Macro Bottom/Top Signals
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TARVIS Labs LLC

//@version=5

// a script to determine macro Bitcoin bottoms to accumulate and tops to sell 
// with warnings provided of local tops

//@version=5
indicator(title="TARVIS Labs - Bitcoin Macro Bottom/Top Signals", shorttitle="TARVIS Labs btc macro bottom/top signals", overlay=true, timeframe="1D", timeframe_gaps=true)

src = input(close, title="Source")

len1 = int(700)
len2 = int(18)
len3 = int(63)
len4 = int(12)
len5 = int(52)
len6 = int(12)

// long term EMA for overall run
ema1 = ta.ema(src, len1)

// major cross pairing
ema2 = ta.ema(src, len2)
ema3 = ta.ema(src, len3)

// major cross pairing to rebuy in
ema4 = ta.ema(src, len4)
ema5 = ta.ema(src, len5)

// helper in beginning bull run warnings
ema6 = ta.ema(src, len6)

// bottom MACD
fast_length = int(168)
slow_length = int(364)
signal_length = int(6)
fast_ma = ta.ema(src, fast_length)
slow_ma = ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = ta.ema(macd, signal_length)

// Top MACD
fast_length2 = int(63)
slow_length2 = int(133)
signal_length2 = int(1)
fast_ma2 = ta.ema(src, fast_length2)
slow_ma2 = ta.ema(src, slow_length2)
macd2 = fast_ma2 - slow_ma2
signal2 = ta.ema(macd2, signal_length2)

// local top warning MACD
fast_length3 = int(30)
slow_length3 = int(65)
signal_length3 = int(4)
fast_ma3 = ta.ema(src, fast_length3)
slow_ma3 = ta.ema(src, slow_length3)
macd3 = fast_ma3 - slow_ma3
signal3 = ta.ema(macd3, signal_length3)


// beginning of bull run local top warning MACD
fast_length4 = int(9)
slow_length4 = int(19)
signal_length4 = int(6)
fast_ma4 = ta.ema(src, fast_length4)
slow_ma4 = ta.ema(src, slow_length4)
macd4 = fast_ma4 - slow_ma4
signal4 = ta.ema(macd4, signal_length4)

// bottom
plot(signal[1] < signal ? src < ema1 ? src : na : na, title='Accumulation Zone Indicator', color=#DAF7A6, style = plot.style_areabr, linewidth = 2)
plotchar(ta.crossover(fast_ma4, slow_ma4) ? signal[1] < signal ? src < ema1 ? src : na : na : na, title='Strong Buy in Accumulation Zone Indicator', color=#013220, text = 'strong buy', location='Top')
plot(ta.crossover(fast_ma4, slow_ma4) ? signal[1] < signal ? src < ema1 ? src : na : na : na, color=#013220, title='Strong Buy in Accumulation Zone Indicator', style = plot.style_areabr, linewidth = 2)

// end
plot(ta.crossunder(ema2, ema3) ? ema1[7] * 1.015 < ema1 ? src : na : na, title='End of Bull Run Indicator', color=#581845, style = plot.style_circles, linewidth = 6)
plotchar(ta.crossunder(ema2, ema3) ? ema1[7] * 1.015 < ema1 ? src : na : na, title='End of Bull Run Indicator', color=#581845, text = 'end', location='Top')

// warnings
plot(ema6[1] >= ema6 ? ema2 > ema3 ? ema1[7] * 1.01 < ema1 ? signal4[1] > signal4 ? src : na : na : na : na, title='Bull Run Local Top Indicator', color=#FFA500, style = plot.style_areabr, linewidth = 2)
plot(ema2 > ema3 ? ema1[7] * 1.025 < ema1 ? signal3[1] > signal3 ? src : na : na : na, color=#FF5733, title='Local Top Near Bull Run Top Indicator', style = plot.style_areabr, linewidth = 2)

// rebuy in
plot(ta.crossover(ema4, ema5) ? ema2 > ema3 ? signal3[1] < signal3 ? src : na : na : na, title='Opportunity to Buy Back in Indicator', color=#0000FF, style = plot.style_areabr, linewidth = 2)
plotchar(ta.crossover(ema4, ema5) ? ema2 > ema3 ? signal3[1] < signal3 ? src : na : na : na, title='Opportunity to Buy Back in Indicator', color=#0000FF, text = 'buy', location='Top')

// top
plot(ema3[1] >= ema3 ? ema2 > ema3 ? ema1[7] * 1.03 < ema1 ? signal2[1] > signal2 ? src : na : na : na : na, title='Top is Likely In Indicator', color=#C70039, style = plot.style_areabr, linewidth = 2)
