How TradingView Recurring Investment Alerts Are Created

Mostly for recurring investment we use platforms like Robinhood who just generates the orders based on batch process. The orders are not generated at the best pricing point. So what we can do is to get the alert setup in such a manner that buy price point is generated when a downtrend is over. There are literally 100s of ways/indicators but we will use the MACD Histogram values here. If you apply MACD indicator in TradingView, you will see 4 zones: red, pink, light green and green. We trigger the alert when the price had moved substantially through red zones and passed a pink histogram. we will reuse the same example from the other post:

If you are new to TradingView then please go through some videos on what TradingView is and how to create a pine script. Please find below the modified MACD indicator pine script below:

study(title="MACD Histogram", shorttitle="MACD Histogram", resolution="")

// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Oscillator MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"])
sma_signal = input(title="Signal Line MA Type", type=input.string, defval="EMA", options=["SMA", "EMA"])

// Plot colors
col_macd = input(#2962FF, "MACD Line  ", input.color, group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", input.color, group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", input.color, group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", input.color, group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", input.color, group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", input.color, group="Histogram", inline="Below")

// Calculating
fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal

plot(hist, title="Histogram", style=plot.style_columns,>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ),0))

plot(macd, title="MACD",, 0))

plot(signal, title="Signal",, 0))

alertcondition(condition=(hist>=0 ? (false) : (((macd < 0) and (signal < 0) and (hist[1] < hist) and (hist[1] <= hist[2]) and (hist[2] <= hist[3]) and (hist[3] <= hist[4])) ? true : false)), title="Pink")

plotCharCondition = crossover(macd, signal)

plotchar(series=plotCharCondition,, color=#ffffff, char=shape.cross)