How to create a Custom ATR with EasyLanguage

In this tutorial, you’ll learn how to create the custom sloped and smoothed version of the Average True Range for TradeStation and MultiCharts in EasyLanguage and PowerLanguage.

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

In this tutorial, we’ll walk you through creating and modifying the Average True Range ATR indicator.

Average True Range for TradeStation – Sloped & Smoothed

Standard Average True Range for TradeStation 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);

RELATED ARTICLES:

Smoothed Average True Range for TradeStation in EasyLanguage

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 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 increases and the Average True Range is over his 50-period Moving Average, the color becomes Red; when the volatility decreases, the color becomes 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:

Average True Range for MultiCharts – Sloped & Smoothed

Standard Average True Range in PowerLanguage for MultiCharts

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 in PowerLanguage for MultiCharts

Consider you want to flatten your MultiCharts Indicator. It’s simple. To smooth an Average True Range in 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 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 that you can see the difference with the standard green.

Volatility phases with Average True Range in PowerLanguage for MultiCharts

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 add a Moving Average to identify 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 increases and the Average True Range is over his 50-period Moving Average, the color becomes Red; when the volatility decreases, the color becomes 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: