OPEN-SOURCE SCRIPT

Dynamic SMA Above and Below Candles By (Fahad Bashir)

//version=5
indicator("Dynamic SMA Above and Below Candles", overlay=true, max_lines_count=500)

// Input parameters
sma_length = input.int(21, "SMA Length", minval=1)
offset_atr_multiplier = input.float(1.5, "Offset ATR Multiplier", step=0.1)
atr_length = input.int(14, "ATR Period", minval=1)

// Calculations
sma = ta.sma(close, sma_length)
atr = ta.atr(atr_length)
dynamic_offset = atr * offset_atr_multiplier
upper_sma = sma + dynamic_offset // Upper SMA above the candles
lower_sma = sma - dynamic_offset // Lower SMA below the candles

// Plotting
plot(upper_sma,
color=color.new(#FF4500, 0),
linewidth=2,
title="Dynamic SMA Above",
style=plot.style_line)
plot(lower_sma,
color=color.new(#00BFFF, 0),
linewidth=2,
title="Dynamic SMA Below",
style=plot.style_line)

// Price relationship visualization
bgcolor(close > upper_sma ? color.new(color.red, 90) : color.new(color.green, 90))

免責聲明