// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/// © celing
//
@version=5
indicator("CELING HIGH LOW BAND", overlay=true, timeframe="")
import TradingView/ta/7
// MOVING AVERAGES
// Exponential Moving Averge 21
input_ema21_length = input(21, title="EMA length", group="EMA")
ema21_high = ta.ema(high, input_ema21_length)
ema21_low = ta.ema(low, input_ema21_length)
// Simple Moving Average 50
input_sma50_length = input(50, title="SMA length", group="EMA")
sma50 = ta.sma(close, input_sma50_length)
// CONDITIONS
input_lookback_length = input(4, title="Length for determining rising/falling MA", group="EMA", tooltip="Number of bars used to compare current moving average price with. Is the current price higher than X bars back the moving average is rising. Is the current price lower than X bars back the moving average is falling. ")
// BULLISH CONDITIONS
// Price above/below high low band
condition_ema21_up = close >= ema21_high
// Condition: SMA50 is rising
condition_sma50_uptrend = sma50 >= sma50[input_lookback_length]
// Condition: EMA21 is greater or equal SMA50
condition_ema21_geq_sma50 = ema21_low >= sma50
//BEARISH CONDITIONS
// Price above/below high low band
condition_ema21_down = close <= ema21_low
// Codition: SMA50 is falling
condition_sma50_downtrend = sma50 <= sma50[input_lookback_length]
// Condition: EMA21 is less or equal SMA50
condition_ema21_seq_sma50 = ema21_low <= sma50
// SIGNALS FOR ALERTS
// Up signal when both EMA21 and SMA50 are rising and EMA21 is greater/equal than SMA50
signal_up = condition_ema21_up and condition_sma50_uptrend and condition_ema21_geq_sma50
// Down signal when both EMA21 and SMA50 are falling and EMA21 is less/equal than SMA50
signal_down = condition_ema21_down and condition_sma50_downtrend and condition_ema21_seq_sma50
// COLORS FOR HIGH LOW BAND
// Defining Colors
color_green = color.rgb(76, 175, 79, 50)
color_neutral = color.rgb(113, 113, 113, 50)
color_red = color.rgb(175, 76, 76, 50)
// Inputs for settings
input_color_green = input(color_green, title="Bullish Color", group="Colors")
input_color_neutral = input(color_neutral, title="Neutral Color", group="Colors")
input_color_red = input(color_red, title="Bearish Color", group="Colors")
// Setting colors
color_plot_up = signal_up ? input_color_neutral : input_color_red
color_plot_down = signal_down ? input_color_neutral : input_color_green
// PLOT HIGH LOW BAND
plot_high = plot(ema21_high, color=color_plot_up, title="EMA high")
plot_low = plot(ema21_low, color=color_plot_down, title="EMA low")
fill(plot_high, plot_low, color=signal_up ? input_color_green : signal_down ? input_color_red : input_color_neutral)
// ALERT CONDITIONS
alertcondition(signal_up[1], title="⬆️ Bullish Signal")
alertcondition(signal_down[1], title="⬇️ Bearish Signal")