ATR Bands with ATR Cross + InfoTableOverview
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, 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 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!
Sizing
Scaled Order Sizing and Take Profit Target ArraysWOAH Order Scaling!
This Provides a user with methods to create a list of profit targets and order sizes which grow or shrink. For size, the will add up to specific sum. for Targets they will include the first and last, and can lean towards either, to scale the order grid.
And thanks to @Hoanghetti for the markdown, i've included a basic usage example within the hover , o you don't need to search for the usage example, simply import, and when writing, the code hint contains a full example.
scaled_sizes(total_size, count, weight, min_size, as_percent)
create an array of sizes which grow or shrink from first to last
which add up to 1.0 if set the as_percent flag , or a total value / sum.
Parameters:
total_size : (float) total size to divide ito split
count : (int ) desired number of splits to create
weight : (float) a weight to apply to grow or shrink the split either towards the last being most, or the first being most, or 1.0 being each is equally sized as 1/n count
min_size : (float) a minimum size for the smallest value (in value of ttotal_size units)
as_percent : (float) a minimum size for the smallest value (in value of total_size units)
Returns: Array of Sizes for each split
scaled_targets(count, weight, minimum, maximum)
create a list of take profitt targets from the smallest to larget distance
Parameters:
count : (int ) number of targets
weight : (float) weight to apply to growing or shrinking
minimum : (float) first value of the output
maximum : (float) last value of the output
Returns: Array of percentage targets
Position Sizing w/ ADR&ATR TrackingScript to use for position sizing based on portfolio size, max position, and max loss inputs. The option to use custom entry and stop are available, but default to last price for entry, and Low of Day (LoD) for stop. The ATR % is a measure of the low of day to current price as a percentage move.
Credit to LonesomeTheBlue for the base code on position sizing and TheScrutiniser/GlinckEastwoot for ADR formula
-Nelgoth, best of luck
Position Size Calculator - Fixed Dollar amount, point value ATRHello Traders,
A very simple code aiming to help you size your position, according to the amount you're accepting to lose AND the current volatility ATR.
Why is it important to use ATR size ? Markets move, and having fixed stoploss values will lead to getting stopped out in case of volatility increase.
You also need to size down your trades in case of more volatily, as more points can be taken or lost.
Hope it helps!
Kudos to Racer9 who inspired me :
Minimum Average True RangeI use ATR a lot when designing trading strategies, this way the strategy adjusts to the instrument in most cases instead of me plugging in special numbers.
However, ATR itself could get spiked by some violent moves. For this I have created MinATR which I am publishing here.
It is effectively ATR + minimum ATR over the last "Min Length" bars. (this is a parameter which I have defaulted to 50).
So use this the same way you use ATR, but it will also show the min ATR over the last "Min Length" periods.
Distribution Position Size Panel
This panel is an example position size panel that I prepared and I consider the rates reasonable.
I have prepared this panel so that the money allocated to the investment ends 14 consecutive signals.
The sum of the ratios is 100 units.
You can adjust your positions according to this panel.
The first steps are low rates.
If the phrases are strong, you can specify a position size from the lower digits.
Likewise, when you make a big profit, you can empty your profits in the lower steps.
In the event of a color change, you can return to the beginning or lower limit.
NOTE: This script is an auxiliary command to the distribution blocks script,
if you want to use another script, you can add distribution days to yours.
14 th stake does not appear in the preview, you need to reduce the size of the distribution blocks indicator slightly.
Rafael Zioni's examples of the panels helped a lot, thanks to him.
Stay tuned ! Regards , Noldo.
Simplified SizingEnsure you Uncheck #1 , #2, #3 in the STYLE tab or it draws the lines you only need the numbers for.
The first number is the deviation from the EMA , anything below 1.75 == 1. (less than 0.75 % deviation)
NOTE: The fill area turns yellow @ 1.50 and red above 2.75
There are steps built in to slightly lower share size when specific levels of divergence register:
From 1.75 to 10 , 1 == 1.10 (10% reduction)
From 10 and up, 1 == 1.20 (20% reduction)
The second number is the Average True Range , calculated by the input length (RMA smoothed) and a multiplier (in decimal form).
NOTE: From 930-936 this value is multiplied by 1.5
The third number is the max share size.
The 4th number is the lot price if you take a position at the max size.
INPUTS:
ATR Length
EMA Length for divergence calculation
ATR Multiplier (0.1 - 10)
Equity in account
Max loss per trade.
Good Luck!
Sizing GuideThis indicator helps you defining your max sizing, depending on the max $$$ amount you're willing to risk against a specific exponential moving average (or VWAP, default is the 13ema).
You can define your max risk amount and your max allowed sizing. The indicator would suggest the best sizing in order to risk only up to the amount you are comfortable with on a potential trade.
Moreover, the column bar would turn yellow/red if the divergence is above a certain threshold (default are yellow > 1.50% and red > 2.75%, green otherwise).