OPEN-SOURCE SCRIPT

Multi Period ATR __ahamd__razavi__


### Code Breakdown

1. **Indicator Declaration**:
```pinescript
//version=6
indicator(title="Multi-Period ATR", shorttitle="ATR Multi", overlay=false, timeframe="", timeframe_gaps=true)
```
- `//version=6`: This specifies that the script uses version 6 of Pine Script.
- `indicator(...)`: This function defines the properties of the indicator, including its title, short title, whether it overlays on the price chart (`overlay=false` means it will be in a separate pane), and settings for timeframes.

2. **Input for Smoothing Method**:
```pinescript
smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
```
- This line creates an input option for users to select the smoothing method for the ATR calculation. The default is set to "RMA" (Relative Moving Average), but users can choose from RMA, SMA (Simple Moving Average), EMA (Exponential Moving Average), or WMA (Weighted Moving Average).

3. **Function to Calculate Moving Average**:
```pinescript
ma_function(source, length) =>
switch smoothing
"RMA" => ta.rma(source, length)
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
=> ta.wma(source, length)
```
- This function takes two parameters: `source` (the data series to smooth) and `length` (the period for the moving average).
- It uses a `switch` statement to determine which smoothing method to apply based on the user's selection.

4. **Calculating ATR for Multiple Periods**:
```pinescript
atr_14 = ma_function(ta.tr(true), 14)
atr_55 = ma_function(ta.tr(true), 55)
atr_100 = ma_function(ta.tr(true), 100)
atr_200 = ma_function(ta.tr(true), 200)
atr_500 = ma_function(ta.tr(true), 500)
atr_1000 = ma_function(ta.tr(true), 1000)
atr_2000 = ma_function(ta.tr(true), 2000)
atr_3000 = ma_function(ta.tr(true), 3000)
atr_4999 = ma_function(ta.tr(true), 4999)
```
- Here, the script calculates the ATR for various periods (14, 55, 100, etc.) using the `ma_function`.
- `ta.tr(true)` computes the True Range, which is used as input for calculating ATR.

5. **Plotting ATR Lines**:
```pinescript
plot(atr_14, title="ATR (14)", color=color.red)
plot(atr_55, title="ATR (55)", color=color.orange)
plot(atr_100, title="ATR (100)", color=color.yellow)
plot(atr_200, title="ATR (200)", color=color.green)
plot(atr_500, title="ATR (500)", color=color.blue)
plot(atr_1000, title="ATR (1000)", color=color.purple)
plot(atr_2000, title="ATR (2000)", color=color.gray)
plot(atr_3000, title="ATR (3000)", color=#363a45)
plot(atr_4999, title="ATR (4999)", color=color.rgb(55, 81, 154))
```
- Each `plot` function call draws a line on the chart for each calculated ATR value. Each line has a specific color and a title indicating its period.

### Summary

This script provides a comprehensive view of market volatility by plotting multiple ATR lines over different periods on TradingView. Traders can use this information to assess market conditions and make informed trading decisions based on volatility trends. The ability to select different smoothing methods enhances flexibility and allows traders to customize their analysis according to their preferences.
statistics

Open-source Skript

Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun das Script auch andere Trader verstehen und prüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Möchten Sie dieses Skript auf einem Chart verwenden?

Haftungsausschluss