code created by gpt
This commit is contained in:
parent
277492c7f8
commit
b4ed0c6906
@ -1,53 +1,31 @@
|
||||
//@version=5
|
||||
indicator("Sunny Bands", shorttitle="SunnyB", overlay=true, format=format.price, precision=2)
|
||||
indicator(title="SunnyBands Indicator", shorttitle="SunnyBands", overlay=true)
|
||||
|
||||
// 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)
|
||||
// Inputs
|
||||
length = input.int(50, title="DMA Length")
|
||||
atr_multiplier = input.float(1.5, title="ATR Multiplier")
|
||||
smooth_factor = input.int(2, title="Smoothing Factor")
|
||||
|
||||
// Double EMA (DMA) calculation matching Python implementation
|
||||
// Double EMA (DMA)
|
||||
ema1 = ta.ema(close, length)
|
||||
dma = ta.ema(ema1, smooth_factor)
|
||||
|
||||
// ATR calculation equivalent to Python version
|
||||
// ATR Calculation
|
||||
atr = ta.atr(length)
|
||||
|
||||
// Calculate bands
|
||||
// Upper & Lower 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)
|
||||
// Bullish & Bearish Signals
|
||||
bullish_signal = ta.crossover(close, lower_band) // Close crosses above lower band
|
||||
bearish_signal = ta.crossunder(close, upper_band) // Close crosses below upper band
|
||||
|
||||
// Store plot references for fill
|
||||
dma_plot = plot(dma, "DMA", color=color.new(#009688, 0), linewidth=2)
|
||||
upper_plot = plot(upper_band, "Upper Band", color=color.new(#FF5252, 0), linewidth=2)
|
||||
lower_plot = plot(lower_band, "Lower Band", color=color.new(#4CAF50, 0), linewidth=2)
|
||||
// Plotting Bands
|
||||
plot(dma, title="DMA", color=color.blue, linewidth=2)
|
||||
plot(upper_band, title="Upper Band", color=color.red, linewidth=2)
|
||||
plot(lower_band, title="Lower Band", color=color.green, linewidth=2)
|
||||
|
||||
// Correct fill using plot references
|
||||
fill(upper_plot, lower_plot, color.new(#673AB7, 90), "Band Area")
|
||||
|
||||
// Signal markers
|
||||
plotshape(
|
||||
bullish,
|
||||
"Bullish Signal",
|
||||
shape.triangleup,
|
||||
location.belowbar,
|
||||
color.green,
|
||||
size.small
|
||||
)
|
||||
|
||||
plotshape(
|
||||
bearish,
|
||||
"Bearish Signal",
|
||||
shape.triangledown,
|
||||
location.abovebar,
|
||||
color.red,
|
||||
size.small
|
||||
)
|
||||
|
||||
// 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")
|
||||
// Entry & Exit Markers
|
||||
plotshape(bullish_signal, location=location.belowbar, style=shape.triangleup, color=color.green, size=size.small, title="Bullish Signal")
|
||||
plotshape(bearish_signal, location=location.abovebar, style=shape.triangledown, color=color.red, size=size.small, title="Bearish Signal")
|
||||
Loading…
Reference in New Issue
Block a user