feat: Add Pine Script implementation of SunnyBands indicator
This commit is contained in:
parent
1fe27d41da
commit
072fba4006
42
pinescripts/Sunny_Bands.pine
Normal file
42
pinescripts/Sunny_Bands.pine
Normal file
@ -0,0 +1,42 @@
|
||||
//@version=5
|
||||
indicator("Sunny Bands", shorttitle="SunnyB", overlay=true, format=format.price, precision=2)
|
||||
|
||||
// Input parameters matching Python class
|
||||
length = input.int(50, "DMA Length", minval=1)
|
||||
atr_multiplier = input.float(1.5, "ATR Multiplier", minval=0.1, step=0.1)
|
||||
smooth_factor = input.int(2, "Smoothing Factor", minval=1)
|
||||
|
||||
// Double EMA (DMA) calculation matching Python implementation
|
||||
ema1 = ta.ema(close, length)
|
||||
dma = ta.ema(ema1, smooth_factor)
|
||||
|
||||
// ATR calculation equivalent to Python version
|
||||
atr = ta.atr(length)
|
||||
|
||||
// Calculate bands
|
||||
upper_band = dma + (atr * atr_multiplier)
|
||||
lower_band = dma - (atr * atr_multiplier)
|
||||
|
||||
// Signal detection using crossovers
|
||||
bullish = ta.crossover(close, lower_band)
|
||||
bearish = ta.crossunder(close, upper_band)
|
||||
|
||||
// Plotting with similar colors to Python version
|
||||
plot(dma, "DMA", color=color.new(#009688, 0), linewidth=2)
|
||||
plot(upper_band, "Upper Band", color=color.new(#FF5252, 0), linewidth=2)
|
||||
plot(lower_band, "Lower Band", color=color.new(#4CAF50, 0), linewidth=2)
|
||||
|
||||
// Signal markers
|
||||
plotshape(bullish, "Bullish Signal", style=shape.triangleup,
|
||||
location=location.belowbar, color=color.green, size=size.small)
|
||||
plotshape(bearish, "Bearish Signal", style=shape.triangledown,
|
||||
location=location.abovebar, color=color.red, size=size.small)
|
||||
|
||||
// Background between bands like Python version
|
||||
fill(upper_band, lower_band, color.new(#673AB7, 90), title="Band Area")
|
||||
|
||||
// Alerts equivalent to get_signals() method
|
||||
alertcondition(bullish, "Bullish Signal Detected",
|
||||
"Sunny Bands: Bullish crossover of lower band")
|
||||
alertcondition(bearish, "Bearish Signal Detected",
|
||||
"Sunny Bands: Bearish crossunder of upper band")
|
||||
Loading…
Reference in New Issue
Block a user