Support Board
Date/Time: Sun, 15 Jun 2025 17:27:44 +0000
Post From: pinescript code conversion
[2025-06-03 12:24:10] |
User411320 - Posts: 331 |
// Input Groups var string apz_settings = "════════ APZ Settings ════════" var string visual_settings = "════════ Visualization Settings ════════" // Descriptions for inputs (Tooltips) tooltip_apz_length = "Length of the APZ calculation period. Higher values create smoother signals but respond slower to price changes." tooltip_threshold = "Multiplier for volatility bands. Higher values create wider bands and generate fewer signals." tooltip_smooth = "Smoothing period for the typical price. Higher values reduce noise but increase lag." tooltip_bar_coloring = "Enable or disable bar coloring based on trend direction." // APZ Settings length = input.int(21, "APZ Length", minval=1, group=apz_settings, tooltip=tooltip_apz_length) threshold = input.float(2.0, "Threshold", minval=0.1, step=0.1, group=apz_settings, tooltip=tooltip_threshold) smooth = input.int(5, "Smoothing", minval=1, group=apz_settings, tooltip=tooltip_smooth) // Visualization Settings bullcolor = input.color(#00ffaa, "Bullish Color", group=visual_settings) bearcolor = input.color(#ff0000, "Bearish Color", group=visual_settings) bar = input.bool(false, "Color Bars?", group=visual_settings, tooltip=tooltip_bar_coloring) // ╔════════════════════════════════╗ // // ║ APZ CALCULATIONS ║ // // ╚════════════════════════════════╝ // // Price and volatility calculations float typical = hlc3 float volatility = ta.ema(math.abs(typical - typical[1]), length) float upperBand = ta.ema(typical, smooth) + threshold * volatility float lowerBand = ta.ema(typical, smooth) - threshold * volatility // Trend Detection and APZ Calculation float trend = 0 trend := typical > upperBand[1] ? 1 : typical < lowerBand[1] ? -1 : nz(trend[1]) // ╔════════════════════════════════╗ // // ║ VISUALIZATION ║ // // ╚════════════════════════════════╝ // // Bullish/Bearish Trend l1 = plot(1, "Bullish Trend", display=display.none, color=color.new(bullcolor, 0)) l2 = plot(-1, "Bearish Trend", display=display.none, color=color.new(bearcolor, 30)) // Neutral Line hline(0, color=color.new(color.white, 50), title="Zero Line") // APZ Trend Plot z = plot(trend, "APZ Trend", trend > 0 ? bullcolor : bearcolor, linewidth=4, style=plot.style_stepline_diamond) mid = plot(0, color=color.new(color.white, 50), display=display.none) // Fill between trend and zero line fill(z, mid, trend > 0 ? trend : 0, trend > 0 ? 0 : trend, trend > 0 ? color.new(bullcolor, 10) : na, trend > 0 ? na : color.new(bearcolor, 10)) // Signal Markers plotshape(ta.crossover(trend, 0), location = location.belowbar, style = shape.triangleup, size = size.tiny, text = "⤻", textcolor = chart.fg_color, color = bullcolor, title = "Mean Reversion Up", force_overlay = true ) plotshape(ta.crossunder(trend, 0), location = location.abovebar, style = shape.xcross, size = size.tiny, text = "↷", textcolor = chart.fg_color, color = bearcolor, title = "Mean Reversion Down", force_overlay = true ) barcolor(bar ? trend > 0 ? bullcolor : bearcolor : na) |