The Average True Range (ATR) study takes the moving average of the true range over the specified period.

Definitions:

- True Range = True High - True Low
- True High = The greater of the current bar's high or the previous bar's close
- True Low = The lesser of the current bar's low or the previous bar's close

The famous turtles initially used the function, but there is a lot we can do with it today.

**True Range Risk Study - TRrisk**

A very common approach to money management is that the range (or true range) of a bar defines an implied risk in entering a technically driven trade. If you enter a trade on a bar on a technical signal, you have to wait at least another bar until an exit signal can occur (Exception stops). The average range of the bars you are trading gives you an idea of the risk involved trading this market. Now I am using the money I want to risk divided by the implied risk measured.

Floor(risk / PriceToDollar(ATR(@,Sim,10)))

If I am willing to risk 10.000$ per trade – in this example I can trade 7 lots at the moment.

This was discussed in more detail in an earlier article I wrote - https://news.cqg.com/blogs/coding/2013/08/atr-based-quantity-and-risk.

**Another interesting study: TR Oscillator**

The classic Oscillator study plots the difference between two moving averages of different lengths or types. The difference of two moving averages with different sensitivities to market action provides an indication of the development of a change in the market environment, such as the emergence of a new trend or a trend reversal.

Calculation for Oscillator

OSC = MA1 - MA2

An Oscillator (OSC) is the difference between two moving averages. The Oscillator is calculated by subtracting the value of the Oscillator's second Moving Average from the value of the Oscillator's first Moving Average.

Why not build an oscillator to plot the difference of two moving averages using different length based on True Range?

Here is the code:

W1:= MA(TrueRange(@),Wei,WMA1); W2:= MA(TrueRange(@),Wei,WMA2); X1:= MA(TrueRange(@),Exp,WMA1); X2:= MA(TrueRange(@),Exp,WMA2); IF(EXP, X2-X1,W2-W1 )

I had a hard time deciding between weighted moving average and exponential moving average, which is why the code has both options.

You can change the length of the averages and check EXP if you prefer.

**Range by Side – TRside**

Instead of using every bar's full range or true range I thought about measuring the up and down range from the open of each bar. Again I could not decide whether to smooth it with the exponential moving average or the weighted moving average, so I left the choice for the user.

Here is the code:

upw:= MA(High(@)-Open(@),Wei,10); dnw:= MA(Open(@) - Low(@),Wei,10); upe:= MA(High(@)-Open(@),Exp,10); dne:= MA(Open(@) - Low(@),Exp,10); IF(EXP,upe-dne , upw - dnw)

You can change the length of the average and check EXP if you prefer.

**True Range Levels – TRlevel**

The last study of this article uses a mid-price and the add or subtract from the true range with a factor. The red line stays intact as long its values are ascending and the green line stays intact only if the values are descending. The factor is a decimal figure how many ATRs the stop should be away from the mid line.

The turtles normally used two ATRs – but this chart shows only one ATR.

The code is split into the two lines:

Up-line MP:= MA(Mid(@),Exp,EMA); TR:= MA(TrueRange(@),Exp,EMA); TU:= MP + TR*factor; IF(TU <= TU[-1], TU, none) Dn-Line MP:= MA(Mid(@),Exp,EMA); TR:= MA(TrueRange(@),Exp,EMA); TD:= MP - TR*factor; IF(TD >= TD[-1], TD, none)

As always, all four studies can be downloaded as a component pac for CQG.