EMA 10 & 20 Steep Slope Alert (v6) - Fixed NA//@version=6
indicator("EMA 10 & 20 Steep Slope Alert (v6) - Fixed NA", overlay=true, shorttitle="EMA Slope 10/20")
// Inputs
emaLength1 = input.int(10, "EMA 1 Length", minval=1)
emaLength2 = input.int(20, "EMA 2 Length", minval=1)
lookbackBars = input.int(3, "Bars for slope calculation", minval=1)
slopeThresholdPct = input.float(0.08, "Slope threshold (%/minute)", step=0.01)
requirePriceFilter = input.bool(true, "Require price above/below both EMAs for alerts")
// EMA calculations
ema1 = ta.ema(close, emaLength1)
ema2 = ta.ema(close, emaLength2)
ema1_look = ema1
ema2_look = ema2
// Calculate slopes safely (typed variables + ternary to avoid illegal NA assignment)
float slope1 = (not na(ema1_look) and ema1_look != 0) ? ((ema1 - ema1_look) / ema1_look) * (100.0 / lookbackBars) : na
float slope2 = (not na(ema2_look) and ema2_look != 0) ? ((ema2 - ema2_look) / ema2_look) * (100.0 / lookbackBars) : na
// Steepness conditions (guard against NA)
steepUp = not na(slope1) and not na(slope2) and slope1 >= slopeThresholdPct and slope2 >= slopeThresholdPct
steepDown = not na(slope1) and not na(slope2) and slope1 <= -slopeThresholdPct and slope2 <= -slopeThresholdPct
// Optional price filter
upFilter = close > ema1 and close > ema2
downFilter = close < ema1 and close < ema2
finalUp = steepUp and (requirePriceFilter ? upFilter : true)
finalDown = steepDown and (requirePriceFilter ? downFilter : true)
// Plots & visuals
plot(ema1, title="EMA 10", color=color.new(color.green, 0))
plot(ema2, title="EMA 20", color=color.new(color.red, 0))
plotshape(finalUp, title="Steep Up Signal", style=shape.triangleup, location=location.belowbar, size=size.small, text="UP")
plotshape(finalDown, title="Steep Down Signal", style=shape.triangledown, location=location.abovebar, size=size.small, text="DN")
bgcolor(finalUp ? color.new(color.green, 85) : finalDown ? color.new(color.red, 85) : na)
// Hidden slope plots (appear in data window)
plot(slope1, title="Slope EMA10 (%/min)", display=display.none)
plot(slope2, title="Slope EMA20 (%/min)", display=display.none)
// Alerts
alertcondition(finalUp, title="Steep Uptrend", message="EMA 10 & 20 steep upward slope detected")
alertcondition(finalDown, title="Steep Downtrend", message="EMA 10 & 20 steep downward slope detected")
10
LBR 3-10 OscillatorThis is a variation of MACD popularised by Linda Bradford Raschke. Instead of the regular MACD settings, the this indicator uses simple moving averages, not exponential moving averages, and a setting of 3 for the fast MA, 10 for the slow MA and 16 for the signal line.
The signal line (red) acts as a trend indicator, with crossings of the zero line indicating trend changes, while the MACD line (blue) acts as a short term momentum indicator.
Setups:
- First cross: This is basically selling or buying at the first pullback after a trend change. Buy or sell after the signal line has crossed the zero line and the MACD crosses the signal line for the first time after the trend change. Use price action to time the entry after the pullback — you don't need to wait for the MACD to cross the signal line again.
- Pullback in a trend: The MACD crosses the signal line in the opposite direction of the trend irregardless of when the trend change occurred. Use price action to time the entry.
- Divergence: The MACD line shows a pattern diverging form price (e.g. makes higher lows whereas price makes lower lows). This can be an indication of trend reversal or waning.
In the indicator's input panel there is an option for showing standard deviation bands (turned off by default). MACD line crossing the standard deviation bands can indicate oversold and overbought conditions.
The indicator comes with the following alerts:
- First cross downtrend
- First cross uptrend
- Pullback in downtrend
- Pullback in uptrend
- Trend change down
- Trend change up
Sources:
lindaraschke.net
www.netpicks.com