Buy / Sell alert indicator [Crypto_BCT]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Crypto_BitCoinTrader

//@version=5
indicator(title="Buy / Sell alert [Crypto_BCT]", overlay=true, max_labels_count = 500)

// ATR
atrinput = input(6, "ATR")
atr = ta.atr(atrinput)

// EMA
emainput = input(150, "EMA")
ema = ta.ema(close, emainput)

// RSI
rsi = ta.rsi(close,14)
RSI_Bottom = input(36, "(Buy) RSI low")
rsibuy = rsi<RSI_Bottom
RSI_Top = input(64, "(Sell) RSI High")
rsisell = rsi>RSI_Top

// MFI
mfi = ta.mfi(close,14)
MFI_Bottom = input(30, "(Buy) MFI low")
mfibuy = mfi<MFI_Bottom
MFI_Top = input(70, "(Sell) MFI High")
mfisell = mfi>MFI_Top

// CCI
cci = ta.cci(hlc3, 20)
CCI_Bottom = input(-200, "(Buy) CCI Low")
ccibuy = cci<CCI_Bottom
CCI_Top = input(200, "(Sell) CCI High")
ccisell = cci>CCI_Top

// High-Low Bars
lowbar = input(36, "(Buy) Lowest bar from")
lowclosebar = ta.lowestbars(close, lowbar)
highbar = input(36, "(Sell) Highest bar from")
highclosebar = ta.highestbars(close, highbar)

// EMA bar ago
resultbuyema = 0
int emalow = input.int(30, minval=2, title="(Buy) Lowest EMA bar ago")
for i = 1 to emalow
	if ema[i-1]<ema[i]
		resultbuyema += 1
resultsellema = 0
int emahigh = input.int(30, minval=2, title="(Sell) Highest EMA bar ago")
for i = 1 to emahigh
	if ema[i-1]>ema[i]
		resultsellema += 1

buy = lowclosebar == 0 and rsibuy and mfibuy and ccibuy and open<ema and resultbuyema == emalow and (high-low>atr or low-high>atr)
sell = highclosebar == 0 and rsisell and mfisell and ccisell and open>ema and resultsellema == emahigh and (high-low>atr or low-high>atr)

plot(ema, "EMA")

if buy
    label.new(bar_index, low, yloc = yloc.belowbar, color=color(color.green), style=label.style_triangleup, size=size.tiny)
if sell
    label.new(bar_index, high, yloc = yloc.abovebar, color=color(color.red), style=label.style_triangledown, size=size.tiny)
    
bgcolor(buy ? color.new(color.green,70) : na)
alertcondition(buy, title="Low Price Detected", message="Low Price Detected")
bgcolor(sell ? color.new(color.red,70) : na)
alertcondition(sell, title="High Price Detected", message="High Price Detected")