Wish you could use Average True Range (ATR) on your MultiCharts, but not sure if you can code or modify it? With this tutorial, you will learn how to create and modify the Average True Range (ATR) in PowerLanguage for MultiCharts.

Average True Range ATR is available from every trading platforms, but if you would like to dress up or modify your MultiCharts Indicator, here, you can learn how to do it.

## Standard Average True Range in PowerLanguage

**Step 1: Declare the inputs**

Insert the inputs; this PowerLanguage indicator needs only the period of calculation. An Average True Range ATR of period 14, uses the last close price in the previous 14 candles.

Inputs:

ATRLength( 14 );

**Step 2: Declare the variables**

Insert the variables, MultiCharts will use the ATR variable to store the Average True Range values

Variables:

ATR( 0 ) ;

**Step 3: Calculate the Average True Range**

Here we use a specific PowerLanguage function that does the calc.

ATR = AvgTrueRange( ATRLength ) ;

**Step 4: Plot the indicator**

The final step is to plot the PowerLanguage indicator in your chart. You plot the variable ATR.

Plot1( ATR, “ATR” ) ;

That’s all. Attach the MultiCharts Indicator to the chart, and this is the result:

This indicator shows what you need, but sometimes you need more.

You can modify the style of your PowerLanguage indicator, for example, we can adjust the color and the size of the line

Plot1( ATR, “ATR” , Green, Default, 3);

## Smoothed Average True Range

Consider you want to flatten your MultiCharts Indicator. It’s simple. To smooth an Average True Range with PowerLanguage, you have to create a moving average of the ATR variable. Maybe you could use a 5-period moving average.

Declare another variable:

Variables:

ATR( 0 ),

ATR_SMOOTH( 0 );

To create a 5-period moving average of your MultiCharts indicator, write this:

ATR = AvgTrueRange( ATRLength ) ;

ATR_SMOOTH = Average (ATR, 5);

Finally, Plot the ATR_SMOOTH and not the ATR:

Plot1( ATR_SMOOTH, “ATR SMOOTH” , Red, Default, 3);

The smoothed ATR is red, so you can see the difference with the standard green:

## Volatility phases with Average True Range

The Average True Range calculates the volatility; if you want to know if volatility is increasing or decreasing, you can modify the PowerLanguage code.

With the next simple strings, you will be able to add a Moving Average to identify if the volatility is high or low.

Inputs:

ATRLength( 14 );

Add two variables to calculate the Moving Average and the color of the ATR

Variables:

ATR( 0 ),

MA_ATR ( 0 ),

ATR_Color ( White );

Calculate the ATR and his Moving Average

ATR = AvgTrueRange( ATRLength ) ;

MA_ATR = Average (ATR, 50);

Finally, create the rule to change the color of your PowerLanguage indicator. When the volatility is increasing, and the Average True Range is over his 50-period Moving Average, the color became Red, when the volatility is decreasing the color became Green.

If ATR > MA_ATR then

ATR_Color = Red;

If ATR < MA_ATR then

ATR_Color = Green;

And draw two lines in your MultiCharts chart, the ATR, and his MA

Plot1( ATR, “ATR”, ATR_Color, default, 3 ) ;

Plot2( MA_ATR, “ATR MA”, White, default, 2 ) ;

Now your indicator shows you the volatility phases and becomes more interesting.

Would you like to visualize the volatility phases with a histogram? Only change the last part of your PowerLanguage code.

Only substitute the variables “ATR” and “MA_ATR” with the number “1”.

Plot1( 1, “ATR”, ATR_Color, default, 3 ) ;

Plot2( 1, “ATR MA”, White, default, 2 ) ;

Enter in the customize tab of the MultiCharts Indicator and change the Style, choose Histogram, and change the Weight.

Change the Scaling value, use a fixed scaling, and set the min to “0” and the max to “1”.

Our MultiCharts indicator with Histogram style:

**Download the PowerLanguage MultiCharts Indicator for free!!**

Average True Range Bundle for MultiCharts

#### Editors’ Recommendations: