TARVIS Labs - Alts 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 ALTS bottoms to accumulate and tops to sell 
// with warnings provided of local tops

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

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

len1a = int(200)
len1b = int(300)
len1c = int(700)
len3 = int(36)
len4 = int(18)
len5 = int(63)

// long term EMA for overall run
ema1a = ta.ema(src, len1a)
ema1b = ta.ema(src, len1b)
ema1c = ta.ema(src, len1c)

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

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

// 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(108)
slow_length2 = int(234)
signal_length2 = int(9)
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(9)
slow_length3 = int(36)
signal_length3 = int(9)
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)


val = ta.crossunder(macd2, signal2)
val2 = ta.crossunder(ema4, ema5)


// bottom
plot(ema1a < ema1b ? src < ema1a * .60 ? src : na : na, title='Accumulation Zone Indicator', color=#DAF7A6, style = plot.style_areabr, linewidth = 2)
plot(ema1a < ema1b ? ema1a[7] * .95 > ema1a ? src : na : na, title='Accumulation Zone Indicator', color=#DAF7A6, style = plot.style_areabr, linewidth = 2)
plot(ema3[1] * .98 > ema3 ? ema1a < ema1b ? ema1a[7] * .97 > ema1a ? src : na : na : na, color=#006400, title='Strong Buy in Accumulation Zone Indicator', style = plot.style_areabr, linewidth = 2)

// warnings
plot(ema1c[7] * 1.04 < ema1c ? signal3[1] > signal3 ? src : na : na, color=#FF5733, title='Local Top Near Bull Run Top Indicator', style = plot.style_areabr, linewidth = 2)

// top
plot(ema1c[7] * 1.03 < ema1c ? signal2[1] > signal2 ? ema4 > ema5 ? src : na : na : na, title='Potential End of Bull Run Top Indicator', color=#C70039, style = plot.style_areabr, linewidth = 2)
