stock_system/pinescripts/Three_ATR_EMA.pine

43 lines
1.3 KiB
Plaintext

//@version=5
indicator(title="Three ATR EMA Bands", shorttitle="3ATR EMA", overlay=true)
// Inputs
ema_length = input.int(21, "EMA Length", minval=1)
atr_multiplier = input.float(3.0, "ATR Multiplier", step=0.1)
show_bullish_arrows = input.bool(true, "Show Bullish Signals")
// Calculate EMA
ema = ta.ema(close, ema_length)
// Calculate True Range
tr = math.max(high - low, math.max(math.abs(high - nz(close[1])), math.abs(low - nz(close[1]))))
// Calculate Bands
upper_band = ema + (tr * atr_multiplier)
lower_band = ema - (tr * atr_multiplier)
// Bullish Signal Condition
bullish_signal = close < ema and
close[1] <= lower_band[1] and
close > close[1]
// Plotting
plot(ema, "EMA", color=color.new(#00BFFF, 0))
plot(upper_band, "Upper Band", color=color.new(#FFA500, 0), linewidth=2)
plot(lower_band, "Lower Band", color=color.new(#32CD32, 0), linewidth=2)
// Signal Arrows
plotshape(show_bullish_arrows and bullish_signal ? low : na,
"Bullish Signal",
shape.triangleup,
location.belowbar,
color=color.new(#00FF00, 0),
size=size.small)
// Alerts
alertcondition(bullish_signal, "Bullish Signal Triggered", "3ATR EMA Bullish Signal")
// Strategy Calculations for Visual Reference
if (bullish_signal)
strategy.entry("Bullish", strategy.long)