Might have been done before, I don't know (I couldn't find anything on here), but this is a simple indicator I created that gives the True Range of any length of bars defined by the user. For example, if you set the length to 3, it will give you the True Range of the current bar and the 2 bars before that combined. If you keep the length at the default setting of 1, it simply gives the True Range of the current bar only. Includes an Average True Range line that you can toggle on or off with an adjustable average type and length.
Code for ThinkorSwim:
Screenshot of the indicator set to a length of 18 with a 9 period exponential Average True Range line:
Happy Trading!
Code for ThinkorSwim:
Code:
declare lower;
input Length = 1;
input Average = yes;
input AvgType = averageType.EXPONENTIAL;
input AvgLength = 9;
def tradj = max(max(highest(high, Length) - lowest(low, Length), absValue(highest(high, Length) - close[Length])), absValue(close[Length] - lowest(low, Length)));
def atr = MovingAverage(AvgType, tradj, AvgLength);
plot AverageTrueRange = if Average == yes then atr else double.NaN;
plot AdjustedTrueRange = tradj;
AdjustedTrueRange.setPaintingStrategy(paintingStrategy.HISTOGRAM);
AdjustedTrueRange.setDefaultColor(color.LIGHT_GRAY);
Screenshot of the indicator set to a length of 18 with a 9 period exponential Average True Range line:
Happy Trading!
Last edited: