OPEN-SOURCE SCRIPT

ATR Bands with ATR Cross + InfoTable

Actualizado
Overview
This Pine Script™ indicator is designed to enhance traders' ability to analyze market volatility, trend direction, and position sizing directly on their TradingView charts. By plotting Average True Range (ATR) bands anchored at the OHLC4 price, displaying crossover labels, and providing a comprehensive information table, this tool offers a multifaceted approach to technical analysis.

Key Features:
ATR Bands Anchored at OHLC4: Visual representation of short-term and long-term volatility bands centered around the average price.
OHLC4 Dotted Line: A dotted line representing the average of Open, High, Low, and Close prices.
ATR Cross Labels: Visual cues indicating when short-term volatility exceeds long-term volatility and vice versa.
Information Table: Displays real-time data on market volatility, calculated position size based on risk parameters, and trend direction relative to the 20-period Smoothed Moving Average (SMMA).
Purpose

The primary purpose of this indicator is to:
Assess Market Volatility: By comparing short-term and long-term ATR values, traders can gauge the current volatility environment.

Determine Optimal Position Sizing: A calculated position size based on user-defined risk parameters helps in effective risk management.

Identify Trend Direction: Comparing the current price to the 20-period SMMA assists in determining the prevailing market trend.

Enhance Decision-Making: Visual cues and real-time data enable traders to make informed trading decisions with greater confidence.

How It Works

1. ATR Bands Anchored at OHLC4
Average True Range (ATR) Calculations
Short-Term ATR (SA): Calculated over a 9-period using ta.atr(9).
Long-Term ATR (LA): Calculated over a 21-period using ta.atr(21).

Plotting the Bands
OHLC4 Dotted Line: Plotted using small circles to simulate a dotted line due to Pine Script limitations.
ATR(9) Bands: Plotted in blue with semi-transparent shading.
ATR(21) Bands: Plotted in orange with semi-transparent shading.
Overlap: Bands can overlap, providing visual insights into changes in volatility.
2. ATR Cross Labels
Crossover Detection:
SA > LA: Indicates increasing short-term volatility.
Detected using ta.crossover(SA, LA).
A green upward label "SA>LA" is plotted below the bar.
SA < LA: Indicates decreasing short-term volatility.
Detected using ta.crossunder(SA, LA).
A red downward label "SA<LA" is plotted above the bar.
3. Information Table
An on-chart table provides real-time data with three key metrics:

a. Is ATR-based Price Volatile?
Logic: If SA > LA, then the market is considered volatile.
Display: Shows "Yes" or "No" based on the comparison.

b. Position Size Calculation
Risk Total Amount: User-defined input representing the total capital at risk.
Risk per 1 Stock: User-defined input representing the risk associated with one unit of the asset.
Purpose: Helps traders determine the appropriate position size based on their risk tolerance and current market volatility.

c. Is Price > 20 SMMA?
SMMA Calculation:
Calculated using a 20-period Smoothed Moving Average with ta.rma(close, 20).
Logic: If the current close price is above the SMMA, the trend is considered upward.
Display: Shows "Yes" or "No" based on the comparison.


How to Use
Step 1: Add the Indicator to Your Chart
Copy the Script: Copy the entire Pine Script code into the TradingView Pine Editor.
Save and Apply: Save the script and click "Add to Chart."
Step 2: Configure Inputs
Risk Parameters: Adjust the "Risk Total Amount" and "Risk per 1 Stock" in the indicator settings to match your personal risk management strategy.
Step 3: Interpret the Visuals
ATR Bands
Width of Bands: Wider bands indicate higher volatility; narrower bands indicate lower volatility.
Band Overlap: Pay attention to areas where the blue and orange bands diverge or converge.
OHLC4 Dotted Line
Serves as a central reference point for the ATR bands.
Helps visualize the average price around which volatility is measured.
ATR Cross Labels
"SA>LA" Label:
Indicates short-term volatility is increasing relative to long-term volatility.
May signal potential breakout or trend acceleration.
"SA<LA" Label:
Indicates short-term volatility is decreasing.
May signal consolidation or trend weakening.
Step 4: Utilize the Information Table
Is ATR-based Price Volatile?
Use this as a quick check on market conditions.
Position Size
Incorporate the calculated position size into your trade planning.
Is Price > 20 SMMA?
Use this to confirm trend direction before entering or exiting trades.
Practical Example
Imagine you are analyzing a stock and notice the following:

ATR(9) Crosses Above ATR(21):
A green "SA>LA" label appears.
The info table shows "Yes" for "Is ATR-based price volatile."
Position Size:
Based on your risk parameters, the position size is calculated.
Price Above 20 SMMA:
The info table shows "Yes" for "Is price > 20 SMMA."
Interpretation:

The market is experiencing increasing short-term volatility.
The trend is upward, as the price is above the 20 SMMA.
You may consider entering a long position, using the calculated position size to manage risk.
Customization
Colors and Transparency:
Adjust the colors of the bands and labels to suit your preferences.
Risk Parameters:
Modify the default values for risk amounts in the inputs.
Moving Average Period:
Change the SMMA period if desired.
Limitations and Considerations
Lagging Indicators: ATR and SMMA are lagging indicators and may not predict future price movements.
Market Conditions: The effectiveness of this indicator may vary across different assets and market conditions.
Risk of Overfitting: Relying solely on this indicator without considering other factors may lead to suboptimal trading decisions.

Conclusion
This indicator combines essential elements of technical analysis to provide a comprehensive tool for traders. By visualizing ATR bands anchored at the OHLC4, indicating volatility crossovers, and providing real-time data on position sizing and trend direction, it aids in making informed trading decisions.

Whether you're a novice trader looking to understand market volatility or an experienced trader seeking to refine your strategy, this indicator offers valuable insights directly on your TradingView charts.

Code Summary
The script is written in Pine Script™ version 5 and includes:

Calculations for OHLC4, ATRs, Bands, SMMA:
Uses built-in functions like ta.atr() and ta.rma() for calculations.

Plotting Functions:
plotshape() for the OHLC4 dotted line.
plot() and fill() for the ATR bands.

Crossover Detection:
ta.crossover() and ta.crossunder() for detecting ATR crosses.

Labeling Crossovers:
label.new() to place informative labels on the chart.

Information Table Creation:
table.new() to create the table.
table.cell() to populate it with data.

Acknowledgments
ATR and SMMA Concepts: Built upon standard technical analysis concepts widely used in trading.
Pine Script™: Leveraged the capabilities of Pine Script™ version 5 for advanced charting and analysis.

Note: Always test any indicator thoroughly and consider combining it with other forms of analysis before making trading decisions. Trading involves risk, and past performance is not indicative of future results.

Happy Trading!
Notas de prensa
Updated code to take Long and short ATR lengths from User.
Notas de prensa
Position Size Code Corrected
ATRAverage True Range (ATR)gpsintownpositionsentimentSimple Moving Average (SMA)sizingvolatilty

Script de código abierto

Siguiendo fielmente el espíritu de TradingView, el autor de este script lo ha publicado en código abierto, permitiendo que otros traders puedan entenderlo y verificarlo. ¡Olé por el autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la reutilización de este código en la publicación se rige por las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

¿Quiere utilizar este script en un gráfico?

Exención de responsabilidad