OPEN-SOURCE SCRIPT

Enhanced Stock Ticker with 50MA vs 200MA

150
Description
The Enhanced Stock Ticker with 50MA vs 200MA is a versatile Pine Script indicator designed to visualize the relative position of a stock's price within its short-term and long-term price ranges, providing actionable bullish and bearish signals. By calculating normalized indices based on user-defined lookback periods (defaulting to 50 and 200 bars), this indicator helps traders identify potential reversals or trend continuations. It offers the flexibility to plot signals either on the main price chart or in a separate lower pane, leveraging Pine Script v6's force_overlay functionality for seamless integration. The indicator also includes a customizable ticker table, visual fills, and alert conditions for automated trading setups.
Key Features
Dual Lookback Indices: Computes short-term (default: 50 bars) and long-term (default: 200 bars) indices, normalizing the closing price relative to the high/low range over the specified periods.

Flexible Signal Plotting: Users can toggle between plotting crossover signals (triangles) on the main price chart (location.abovebar/belowbar) or in the lower pane (location.top/bottom) using the Plot Signals on Main Chart option.

Crossover Signals: Generates bullish (Golden Cross) and bearish (Death Cross) signals when the short or long index crosses above 5 or below 95, respectively.

Visual Enhancements:
Plots short-term (blue) and long-term (white) indices in a separate pane with customizable lookback periods.

Includes horizontal reference lines at 0, 20, 50, 80, and 100, with green and red fills to highlight overbought/oversold zones.

Dynamic fill between indices (green when short > long, red when long > short) for quick trend visualization.

Displays a ticker and legend table in the top-right corner, showing the symbol and lookback periods.

Alert Conditions: Supports alerts for bullish and bearish crossovers on both short and long indices, enabling integration with TradingView's alert system.

Technical Innovation: Utilizes Pine Script v6's force_overlay parameter to plot signals on the main chart from a non-overlay indicator, combining the benefits of a separate pane and chart-based signals in a single script.

Technical Details
Calculation Logic:
Uses confirmed bars (barstate.isconfirmed) to calculate indices, ensuring reliability by avoiding real-time bar fluctuations.

Short-term index: (close[1] - lowest(low, lookback_short)) / (highest(high, lookback_short) - lowest(low, lookback_short)) * 100

Long-term index: (close[1] - lowest(low, lookback_long)) / (highest(high, lookback_long) - lowest(low, lookback_long)) * 100

Signals are triggered using ta.crossover() and ta.crossunder() for indices crossing 5 (bullish) and 95 (bearish).

Signal Plotting:
Main chart signals use force_overlay=true with location.abovebar/belowbar for precise alignment with price bars.

Lower pane signals use location.top/bottom for visibility within the indicator pane.

Plotting is controlled by boolean conditions (e.g., bullishLong and plot_on_chart) to ensure compliance with Pine Script's global scope requirements.

Performance Considerations: Optimized for efficiency by calculating indices only on confirmed bars and using lightweight plotting functions.

How to Use
Add to Chart:
Copy the script into TradingView's Pine Editor and add it to your chart.

Configure Settings:
Short Lookback Period: Adjust the short-term lookback (default: 50 bars) to match your trading style (e.g., 20 for shorter-term analysis).

Long Lookback Period: Adjust the long-term lookback (default: 200 bars) for broader market context.

Plot Signals on Main Chart: Check this box to display signals on the price chart; uncheck to show signals in the lower pane.

Interpret Signals:
Golden Cross (Bullish): Green (long) or blue (short) triangles indicate the index crossing above 5, suggesting a potential buying opportunity.

Death Cross (Bearish): Red (long) or white (short) triangles indicate the index crossing below 95, signaling a potential selling opportunity.

Set Alerts:
Use TradingView's alert system to create notifications for the four alert conditions: Long Index Valley, Long Index Peak, Short Index Valley, and Short Index Peak.

Customize Visuals:
The ticker table displays the symbol and lookback periods in the top-right corner.

Adjust colors and styles via TradingView's settings if desired.

Example Use Cases
Swing Trading: Use the short-term index (e.g., 50 bars) to identify short-term reversals within a broader trend defined by the long-term index.

Trend Confirmation: Monitor the fill between indices to confirm whether the short-term trend aligns with the long-term trend.

Automated Trading: Leverage alert conditions to integrate with bots or manual trading strategies.

Notes
Testing: Always backtest the indicator on your chosen market and timeframe to validate its effectiveness.

Optional Histogram: The script includes a commented-out histogram for the index difference (index_short - index_long). Uncomment the plot(index_diff, ...) line to enable it.

Compatibility: Built for Pine Script v6 and tested on TradingView as of May 27, 2025.

Acknowledgments
This indicator was inspired by the need for a flexible tool that combines lower-pane analysis with main chart signals, made possible by Pine Script's force_overlay feature. Share your feedback or suggestions in the comments below, and happy trading!

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.