OPEN-SOURCE SCRIPT

AO + Stoch RSI Combined

200
Key Features:
Fixing hline Errors:
Replaced hline(band_upper, ...) and hline(band_lower, ...) with plot(band_upper, ...) and plot(band_lower, ...) to support dynamic series float values, as hline requires constant input float.

The middle band is plotted at 0 (matching AO’s zero line) using plot(0, ...) for consistency.

Updated the fill function to use plot_upper and plot_lower instead of hline objects.

Preserving AO’s Original Appearance:
The AO histogram uses raw values (ao = ta.sma(hl2, 5) - ta.sma(hl2, 34)), centered around zero, with green (#009688) for rising bars and red (#F44336) for falling bars, matching the standard AO.

Transparency (color.new(..., 50)) ensures K/D lines are visible when overlapping.

A zero line is plotted at 0 for the classic AO look.

Stoch RSI K/D Overlay:
K/D lines are scaled to the AO’s range: k_scaled = (k - 50) * (ao_max / 50), centering them around zero and matching the AO histogram’s amplitude.

Plotted with linewidth=3 for visibility, directly overlaying the histogram bars, “sitting” on them like MACD lines over the MACD histogram.

MACD-Like Design:
AO histogram is the base layer (plot.style_histogram), like the MACD histogram.

Scaled K (blue, #2962FF) and D (orange, #FF6D00) lines overlap the histogram, resembling MACD’s line overlay.

Stoch RSI bands are scaled (band_upper, band_lower) to the AO’s range and plotted dynamically, with a background fill between them.

Same Plot Pane:
AO histogram (raw), scaled K/D lines, scaled Stoch RSI bands, and zero line are plotted in the same pane, with K/D lines directly overlaid on the histogram.

Awesome Oscillator (AO):
Calculates AO as the difference between 5-period and 34-period SMAs of hl2.

Plots raw histogram, colored based on ao_diff.

Alerts for color changes and histogram state changes.

Stochastic RSI:
Calculates RSI (default length 14), Stochastic formula (default length 14), and smooths K (default 3) and D (default 3) with SMAs.

Plots scaled K/D lines and dynamic bands (upper, lower).

Alerts use original K/D values (0-100) for standard thresholds (20/80).

Shorttitle:
AO+StoRSI (9 characters), within the 10-character limit.

Plots:
All elements in a single pane, using color.new for Pine Script version 6 compatibility.

Alerts:
AO: Color changes and histogram state changes.

Stochastic RSI: K crossing D, K exiting oversold (above 20), K entering overbought (below 80).

Usage Instructions:
Copy the script into TradingView’s Pine Script editor.

Customize inputs (e.g., RSI length, Stochastic length, K/D smoothing) as needed.

The AO histogram (original scale, centered at zero) and scaled Stoch RSI K/D lines will appear in the same plot pane, with K/D lines overlaid on the histogram bars in a MACD-like layout.

Histogram transparency (50) and thicker K/D lines (linewidth=3) ensure readability. If the overlap is too cluttered, you can:
Increase transparency (e.g., color.new(..., 70)).

Adjust the K/D scaling factor (e.g., change ao_max / 50 to ao_max / 25).

Set up alerts in TradingView for AO or Stoch RSI conditions.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。