As one of the most important technical indicator, knowing how to create and modify the Average True Range (ATR) in EasyLanguage for TradeStation is a great idea.

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

In this tutorial, we’ll walk you through how to create and modify the Average True Range ATR indicator.

## Standard Average True Range in EasyLanguage Step 1: Declare the inputs

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

Inputs:
ATRLength( 14 );

Step 2: Declare the variables

Insert the variables; the ATR variable contains the value of the Average True Range

Variables:
ATR( 0 ) ;

Step 3: Calculate the Average True Range

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

ATR = AvgTrueRange( ATRLength ) ;

Step 4: Plot the indicator

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

Plot1( ATR, “ATR” ) ;

That’s all. Attach the TradeStation 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 EasyLanguage indicator, for example, we can modify the color and the size of the line

Plot1( ATR, “ATR” , Green, Default, 3); ## Smoothed Average True Range

Say you want to flatten your TradeStation Indicator. Now what? To smooth an Average True Range with EasyLanguage, 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 indicator, write this:

ATR = AvgTrueRange( ATRLength ) ;

ATR_SMOOTH = Average (ATR, 5);

Remember to Plot the ATR_SMOOTH and not the ATR:

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

The smoothed ATR is red so that you can see the difference with the standard green: ## Volatility phases with Average True Range

The Average True Range calculates the volatility, let’s say you want to know if volatility is increasing or decreasing.

With the right EasyLanguage code, 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);

You have to create the rule to change the color of your EasyLanguage 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;

Just remember to draw two lines in your TradeStation 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 complete. If you change the last part of your EasyLanguage code and modify the style of your indicator, you can plot a histogram that shows you if the volatility is high or low.

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 TradeStation Indicator and change the Style, choose Histogram, and change the Weight. Change the Scaling value, use a fixed scaling, and set the min and the max to “1”. This is our TradeStation indicator with Histogram style: 