//@version=5 indicator("lite", overlay = true,explicit_plot_zorder = true) // == COntents: // 1= EMA 50, 100, 200 // 2= EMA 12, 21 // 3= Swing Indicator // = RSI divergence (D) // Show/hide _ema50_100_200 = input(false, "EMA 50, 100 & 200", inline = "most-used", group = "Most used:") _h1_ema50_100_200 = input(false, "H1 EMA 50, 100 & 200", inline = "most-used") _h4_ema50_100_200 = input(false, "H4 EMA 50, 100 & 200", inline = "most-used", group = "Most used:") colEMA50 = input.color( color.rgb(58, 22, 22, 91), 'EMA50 regular', group='Most used:') _ema50 = input(true, "EMA 50 Regular") _ema100 = input(false, "EMA 100") _ema200 = input(false, "EMA 200") ema12_21 = input(false, "EMA 12 & 21", inline = "most-used", group = "Most used:") p_day_hl = input( false, "Prev. Day H/L", group = "Most used:") _ema12_21_cross_alert = input(false, "EMA 12 21 cross alert") _h1_ema50_alert = input( true, "H1 EMA50 Tap/Cross Alert") _h4_ema50_alert = input( true, "H4 EMA50 Tap/Cross Alert") _ema_tap_alert = input(true, "EMA 50, 100, 200 tap alert") _ema_tap_period = input(7, "Lookback in hours EMA Tap Alert to Show", group="Most used:") _swing_indicator = input(false, "Swing Indicator", inline = "most-used", group = "Most used:") de50 = input(false, "Daily EMA 50") int chartTFInMinutes = timeframe.in_seconds() / 60 tf_minute = timeframe.isminutes ? true : false tf_h1 = timeframe.isminutes and timeframe.multiplier == 60 ? true : false tf_h4 = tf_minute ? timeframe.multiplier == 240 ? true : false : false tf_d = timeframe.isdaily ? true : false currentBarOpenElapsed = timenow - time // Age of current bar (in miliseconds) currentBarOpenHour = currentBarOpenElapsed / (1000*60*60) // Age of current bar (in hours) currentBarInAlertRange = currentBarOpenHour <= _ema_tap_period ? true : false //currentBarInAlertRange = currentBarOpenHour > _ema_tap_period*60 ? false : true //currentBarDate = timestamp(year, month, dayofmonth, hour, minute, second) ema12 = ta.ema(close, 12) ema21 = ta.ema(close, 21) ema12_hourly = request.security(syminfo.tickerid, "60", ta.ema(close, 12)) ema21_hourly = request.security(syminfo.tickerid, "60", ta.ema(close, 21)) h1ema50 = request.security(syminfo.tickerid, "60", ta.ema(close, 50)) h1ema100 = request.security(syminfo.tickerid, "60", ta.ema(close, 100)) h1ema200 = request.security(syminfo.tickerid, "60", ta.ema(close, 200)) h4ema50 = request.security(syminfo.tickerid, "240", ta.ema(close, 50)) h4ema100 = request.security(syminfo.tickerid, "240", ta.ema(close, 100)) h4ema200 = request.security(syminfo.tickerid, "240", ta.ema(close, 200)) dailyema50 = request.security(syminfo.tickerid, "1D", ta.ema(close, 50)) ema50 = ta.ema(close, 50) ema100 = ta.ema(close, 100) ema200 = ta.ema(close, 200) isfxchart = syminfo.currency == 'USD' ? true : syminfo.currency == 'JPY' ? true : syminfo.currency == 'CAD' ? true : false notfxchart = syminfo.currency != 'USDT' ? false : true plot( ema12_21 and isfxchart ? ema12 : na, color = color.rgb(4, 125, 125), style=plot.style_line, display = display.all-display.price_scale) plot( ema12_21 and isfxchart ? ema21 : na, color = color.rgb(41, 14, 244, 35), style=plot.style_line, linewidth = 2, display = display.all-display.price_scale) plotshape( _ema12_21_cross_alert ? ta.crossover(ema12_hourly, ema21_hourly) : na, style=shape.circle, size = size.tiny, color=#058185, location = location.belowbar) plotshape( _ema12_21_cross_alert ? ta.crossover(ema21_hourly, ema12_hourly) : na, style=shape.circle, size = size.tiny, color=#d44f6c, location = location.abovebar) plot( _h1_ema50_100_200 ? h1ema50 : na, color=color.rgb(3, 142, 177)) plot( _h1_ema50_100_200 ? h1ema100 : na, color=color.rgb(168, 3, 155)) plot( _h1_ema50_100_200 ? h1ema200 : na, color=color.rgb(9, 5, 248), linewidth = 2) plot( _h4_ema50_100_200 ? h4ema50 : na, color=color.rgb(4, 106, 189)) plot( _h4_ema50_100_200 ? h4ema100 : na, color=color.rgb(168, 3, 155)) plot( _h4_ema50_100_200 ? h4ema200 : na, color=color.rgb(9, 5, 248), linewidth = 2) plot(de50 and tf_d ? dailyema50 : na, color=color.rgb(33, 3, 167), style = plot.style_line) plot( _ema50 and notfxchart ? ema50 : _ema50_100_200 and notfxchart ? ema50 : na, color=colEMA50, display = display.pane) plot( _ema50_100_200 and notfxchart ? ema100 : _ema100 ? ema100 : na, color=colEMA50, linewidth = 1, display = display.pane, style = plot.style_stepline) plot( _ema50_100_200 and notfxchart ? ema200 : _ema200 ? ema200 : na, color=colEMA50, linewidth = 2, display = display.pane) //---- EMA cross/reclaim/tap alert h1_open = request.security(syminfo.tickerid, "60", open) h1_high = request.security(syminfo.tickerid, "60", high) h1_low = request.security(syminfo.tickerid, "60", low) h1_close = request.security(syminfo.tickerid, "60", close) h1_ema50_tapped = currentBarInAlertRange and h1_low <= h1ema50 and h1_close > h1ema50 ? true : false h1_ema100_tapped = currentBarInAlertRange and h1_low <= h1ema100 and h1_close > h1ema100 ? true : false h1_ema200_tapped = currentBarInAlertRange and h1_low <= h1ema200 and h1_close > h1ema200 ? true : false h1_ema_tapped = h1_ema50_tapped or h1_ema100_tapped or h1_ema200_tapped ? true : false h1_ema50_tapped_bearish = currentBarInAlertRange and h1_high >= h1ema50 and h1_open= h1ema100 and h1_open= h1ema200 and h1_open h4ema50 ? true : false h4_ema100_tapped = currentBarInAlertRange and h4_low <= h4ema100 and h4_close > h4ema100 ? true : false h4_ema200_tapped = currentBarInAlertRange and h4_low <= h4ema200 and h4_close > h4ema200 ? true : false h4_ema50_tapped_bearish = currentBarInAlertRange and h4_high >= h4ema50 and h4_close < h4ema50 ? true : false h4_ema100_tapped_bearish = currentBarInAlertRange and h4_high >= h4ema100 and h4_close < h4ema100 ? true : false h4_ema200_tapped_bearish = currentBarInAlertRange and h4_high >= h4ema200 and h4_close < h4ema200 ? true : false h4_ema_tapped = h4_ema50_tapped or h4_ema100_tapped or h4_ema200_tapped ? true : false h4_ema_tapped_bearish = h4_ema50_tapped_bearish or h4_ema100_tapped_bearish or h4_ema200_tapped_bearish ? true : false //barcolor(h1_ema_tapped or h4_ema_tapped ? color.rgb(104, 170, 250) : h1_ema_tapped_bearish or h4_ema_tapped_bearish ? color.rgb(3, 3, 1) : na) plotchar( h1_ema_tapped, "H1 EMA tapped", "●", location.bottom, color.rgb(202, 100, 4)) plotchar( h4_ema_tapped, "H1 EMA tapped", "❖", location.bottom, color.rgb(3, 93, 129)) //plotchar( h4_ema_tapped, location = location.bottom, color=color.rgb(8, 140, 85), text = 'C', textcolor = color.rgb(251, 242, 242, 100)) //plotshape( h4_ema_tapped_bearish, "H4 EMA BEARISH TAP", shape.labeldown, location.bottom, color.rgb(249, 33, 33), text='C', textcolor = color.rgb(248, 245, 245)) //plotchar( h1_ema_tapped, location = location.bottom, color=color.rgb(3, 88, 157), text='c', textcolor = color.rgb(0, 137, 123, 100)) //plotshape( h1_ema_tapped_bearish, "H1 EMA BEARISH TAP", shape.cross, location.bottom, color.rgb(249, 33, 33, 100), text='c', textcolor = color.rgb(249, 40, 40)) //---- FVG //---- RSI divergence //indicator(title="Relative Strength Index", format=format.price, precision=2, timeframe="", timeframe_gaps=true) ma(source, length, type) => switch type "EMA" => ta.ema(source, length) "SMMA (RMA)" => ta.rma(source, length) "WMA" => ta.wma(source, length) "VWMA" => ta.vwma(source, length) //rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings") //rsiSourceInput = input.source(close, "Source", group="RSI Settings") //maTypeInput = input.string("EMA", title="MA Type", options=["EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings") //maLengthInput = input.int(14, title="MA Length", group="MA Settings") rsiLengthInput=14 rsiSourceInput = close maLengthInput = 14 maTypeInput ="EMA" showDivergence =true up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput) down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput) rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down)) rsiMA = ma(rsi, maLengthInput, maTypeInput) // Divergence lookbackRight = 5 lookbackLeft = 5 rangeUpper = 60 rangeLower = 5 bearColor = color.red bullColor = color.green textColor = color.white noneColor = color.new(color.white, 100) plFound = na(ta.pivotlow(rsi, lookbackLeft, lookbackRight)) ? false : true phFound = na(ta.pivothigh(rsi, lookbackLeft, lookbackRight)) ? false : true _inRange(cond) => bars = ta.barssince(cond == true) rangeLower <= bars and bars <= rangeUpper //------------------------------------------------------------------------------ // Regular Bullish // rsi: Higher Low rsiHL = rsi[lookbackRight] > ta.valuewhen(plFound, rsi[lookbackRight], 1) and _inRange(plFound[1]) // Price: Lower Low priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1) bullCondAlert = priceLL and rsiHL and plFound bullCond = showDivergence and bullCondAlert plotshape( bullCond ? rsi[lookbackRight] : na, offset=-lookbackRight, title="Regular Bullish Label", text="D", style=shape.labelup, location=location.bottom, color=bullColor, textcolor=textColor ) //------------------------------------------------------------------------------ // Regular Bearish // rsi: Lower High rsiLH = rsi[lookbackRight] < ta.valuewhen(phFound, rsi[lookbackRight], 1) and _inRange(phFound[1]) // Price: Higher High priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1) bearCondAlert = priceHH and rsiLH and phFound bearCond = showDivergence and bearCondAlert plotshape( bearCond ? rsi[lookbackRight] : na, offset=-lookbackRight, title="Regular Bearish Label", text=" D ", style=shape.labeldown, location=location.top, color=bearColor, textcolor=textColor ) //---- Previous day High/Low notDailyChart = timeframe.isdaily?false:true prev_day_high = request.security(syminfo.tickerid, "D", high[1], gaps=barmerge.gaps_off) prev_day_low = request.security(syminfo.tickerid, "D", low[1], gaps=barmerge.gaps_off) firstBarOfDay = ta.change(time("D")) line_pdh = isfxchart and notDailyChart and p_day_hl ? line.new(bar_index[1], prev_day_high, bar_index+12, prev_day_high, color = color.rgb(3, 118, 172)) : na line_pdl = isfxchart and notDailyChart and p_day_hl ? line.new(bar_index[1], prev_day_low, bar_index, prev_day_low, color = color.rgb(129, 3, 3)) : na // ---------------------------------------------------------------------------------------------------------------------- // -------------------------------------------- // Swing indicator // -------------------------------------------- col_bullish = color.rgb(2, 102, 94, 23) col_bearish = color.rgb(122, 20, 2, 9) ma_fast = request.security( syminfo.tickerid, "240", ta.ema(close, 18), gaps = barmerge.gaps_off) ma_slow = request.security( syminfo.tickerid, "240", ta.ema(close, 22), gaps = barmerge.gaps_off) ema_h4_indicator = request.security( syminfo.tickerid, "240", ta.ema(close, 200), gaps = barmerge.gaps_off) col_swing_indicator = ma_fast > ma_slow ? color.rgb(3, 113, 144, 30) : color.rgb(109, 4, 42, 30) z1 = plot( _swing_indicator ? ma_fast : na, color=color.rgb(3,113,144), style = plot.style_line) z2 = plot( _swing_indicator ? ma_slow : na, color=color.rgb(109,4,42), style = plot.style_line) fill(z1, z2, col_swing_indicator) plot( _swing_indicator ? ema_h4_indicator : na, color=col_swing_indicator, style = plot.style_line)