Bogdan Ciocoiu - Pager
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BogdanCiocoiu

//@version=5

// Update of 09/01/2022
// This revision includes small optimisations

// ► Description
// This script creates the possibility for users to set up alerts on different timeframes when close prices crossover or cross under certain essential exponential moving averages such as 20, 50 or 200. The script shows the fundamental levels where one can set notifications. 
// 
// The current levels are:
// 15min timeframe: when close < EMA 200
// 15min timeframe: when  close > EMA 200
// 5min timeframe: when close < EMA 200
// 5min timeframe: when close > EMA 200
// 60min timeframe: when close < EMA 200
// 60min timeframe: when close > EMA 200
// 
// ► Originality and usefulness
// This tool is helpful because it enables users to use the notification system when specific trends form without actively monitoring price action.
// 
// ► Open-source reuse
// The script only leverages TradingView native functionality.

indicator("Bogdan Ciocoiu - Pager", shorttitle="BC - Pager", overlay=true)
 
_5m_input_on = input(true, "TF1", inline="TF1")
_5m_input_type = input(close, "", inline="TF1")

_15m_input_on = input(true, "TF2", inline="TF2")
_15m_input_type = input(close, "", inline="TF2")

_60m_input_on = input(true, "TF3", inline="TF3")
_60m_input_type = input(close, "", inline="TF3")

_5m_close = request.security(syminfo.tickerid, "5", _5m_input_type)
_5m_ema200 = request.security(syminfo.tickerid, "5", ta.ema(_5m_input_type, 200))

_15m_close = request.security(syminfo.tickerid, "15", _15m_input_type)
_15m_ema200 = request.security(syminfo.tickerid, "15", ta.ema(_15m_input_type, 200))

_60m_close = request.security(syminfo.tickerid, "60", _60m_input_type) 
_60m_ema200 = request.security(syminfo.tickerid, "60", ta.ema(_60m_input_type, 200))

alertcondition(condition=ta.crossover(_5m_close, _5m_ema200), title="5min close > EMA 200", message="5min close > EMA 200")
alertcondition(condition=ta.crossunder(_5m_close, _5m_ema200), title="5min close < EMA 200", message="5min close < EMA 200")

alertcondition(condition=ta.crossover(_15m_close, _15m_ema200), title="15min close > EMA 200", message="15min close > EMA 200")
alertcondition(condition=ta.crossunder(_15m_close, _15m_ema200), title="15min close < EMA 200", message="15min close < EMA 200")

alertcondition(condition=ta.crossover(_60m_close, _60m_ema200), title="60min close > EMA 200", message="60min close > EMA 200")
alertcondition(condition=ta.crossunder(_60m_close, _60m_ema200), title="60min close < EMA 200", message="60min close < EMA 200")

plot(_5m_input_on ? _5m_close : na, "M5 close", color.red, linewidth=1)
plot(_5m_input_on ? _5m_ema200 : na, "M5 EMA 200", color.blue, linewidth=1, style=plot.style_cross)

plot(_15m_input_on ? _15m_close : na, "M15 close", color.yellow, linewidth=1)
plot(_15m_input_on ? _15m_ema200 : na, "M15 EMA 200", color.green, linewidth=1, style=plot.style_cross)

plot(_60m_input_on ? _60m_close : na, "1H close", color.white, linewidth=1)
plot(_60m_input_on ? _60m_ema200 : na, "1H EMA 200", color.purple, linewidth=1, style=plot.style_cross)
