Typical True Range Price for ThinkorSwim

Jman831

Member
This isn't so much an "indicator" but rather a different way of analyzing price that I came up with that can be used within custom indicators. Anyone who follows my threads will notice that I tend to prefer to use Typical Price when analyzing price, meaning rather than using the high, low, close, or open of each candle for my averages and other price indicators, I use hlc3 (aka typical price which = (high + low + close) / 3)). I prefer this for two reasons and that's because:

1. I personally believe (and this is strictly an opinion) typical price is overall more important than the high, low, close, or open by themselves. If you've ever used typical price, you'll often notice that candles can cross below or above an average making it seem like "oh, well it broke the average, so it's likely to continue in the direction that it broke the average", but sometimes going by a single price of a candle such as the close, it can give you a false signal where a "fake out" occurs and the price goes right back above or below the average back in the direction it came from. However, if you go by the typical price instead, you'll notice that the candles can sometimes cross above or below an average while the typical price does not cross above or below the average. The typical price essentially serves as a filter of "fake outs" because although the candle may have broken the average, the typical price might not have broken the average, and you'll often notice that a change in trend/overall direction doesn't truly occur until after the typical price has also broken the average. Fake outs can still occur with the typical price, but it's less likely to occur and when it does occur it's usually because the typical price didn't break the average significantly enough and it's a bit easier to identify a fake out for this reason.

2. Typical price smooths out the price data somewhat by not fluctuating nearly as drastically as say the close would, despite situations where volatility is quite high.

All that being said, I've come up with a different way of analyzing the price that's similar to typical price, but instead of going by the high, low, and close of a single candle, it goes by the high, low, and close of the true range, whatever that may be. True range is always the highest range out of the high - the low, the high - the close of one bar ago, or the close of one bar ago - the low. This way, the range essentially includes the price movement that happened overnight/between candles at all times. So if a candle happens to gap up or down, it will include the price movement that occured from the close of the previous candle, whereas if you went by the range of the current candle alone, it wouldn't include the "empty" space where the gap occurred, hence "true" range.

With what I deem as the "Typical True Range Price", rather than using the high, low, and close of the current candle, it will use the high and low of the true range along with the current close. If the high and the low of the true range happens to be the high and the low of the current candle, then it'll use the typical price of the current candle. If the true range happens to be the high of the current candle and the close of the previous candle, then it'll use the high of the current candle, the close of the previous candle, and the close of the current candle. And finally, if the true range happens to be the close of the previous candle and the low of the current candle, then it'll use the close of the previous candle, the low of the current candle, and the close of the current candle.

The line of code is fairly simple:

Code:
def ttrp = if TrueRange(high, close, low) == high - low then hlc3 else if TrueRange(high, close, low) == high - close[1] then (high + close + close[1]) / 3 else (low + close + close[1]) / 3;
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

This isn't so much an "indicator" but rather a different way of analyzing price that I came up with that can be used within custom indicators. Anyone who follows my threads will notice that I tend to prefer to use Typical Price when analyzing price, meaning rather than using the high, low, close, or open of each candle for my averages and other price indicators, I use hlc3 (aka typical price which = (high + low + close) / 3)). I prefer this for two reasons and that's because:

1. I personally believe (and this is strictly an opinion) typical price is overall more important than the high, low, close, or open by themselves. If you've ever used typical price, you'll often notice that candles can cross below or above an average making it seem like "oh, well it broke the average, so it's likely to continue in the direction that it broke the average", but sometimes going by a single price of a candle such as the close, it can give you a false signal where a "fake out" occurs and the price goes right back above or below the average back in the direction it came from. However, if you go by the typical price instead, you'll notice that the candles can sometimes cross above or below an average while the typical price does not cross above or below the average. The typical price essentially serves as a filter of "fake outs" because although the candle may have broken the average, the typical price might not have broken the average, and you'll often notice that a change in trend/overall direction doesn't truly occur until after the typical price has also broken the average. Fake outs can still occur with the typical price, but it's less likely to occur and when it does occur it's usually because the typical price didn't break the average significantly enough and it's a bit easier to identify a fake out for this reason.

2. Typical price smooths out the price data somewhat by not fluctuating nearly as drastically as say the close would, despite situations where volatility is quite high.

All that being said, I've come up with a different way of analyzing the price that's similar to typical price, but instead of going by the high, low, and close of a single candle, it goes by the high, low, and close of the true range, whatever that may be. True range is always the highest range out of the high - the low, the high - the close of one bar ago, or the close of one bar ago - the low. This way, the range essentially includes the price movement that happened overnight/between candles at all times. So if a candle happens to gap up or down, it will include the price movement that occured from the close of the previous candle, whereas if you went by the range of the current candle alone, it wouldn't include the "empty" space where the gap occurred, hence "true" range.

With what I deem as the "Typical True Range Price", rather than using the high, low, and close of the current candle, it will use the high and low of the true range along with the current close. If the high and the low of the true range happens to be the high and the low of the current candle, then it'll use the typical price of the current candle. If the true range happens to be the high of the current candle and the close of the previous candle, then it'll use the high of the current candle, the close of the previous candle, and the close of the current candle. And finally, if the true range happens to be the close of the previous candle and the low of the current candle, then it'll use the close of the previous candle, the low of the current candle, and the close of the current candle.

The line of code is fairly simple:

Code:
def ttrp = if TrueRange(high, close, low) == high - low then hlc3 else if TrueRange(high, close, low) == high - close[1] then (high + close + close[1]) / 3 else (low + close + close[1]) / 3;
Interesting concept. How would one implement this code?
 
Interesting concept. How would one implement this code?

You can implement it in many different ways. If you want to see the "raw" TTRP, simply add the following code beneath the code provided in the original post:

Code:
plot TypicalTrueRangePrice = ttrp;

One of the ways I like to implement the raw TTRP is by paying attention to the peaks and troughs shown on the chart of the TTRP. In my opinion, the peaks and troughs of the TTRP are more important resistance and support levels than the peaks and troughs of the candles themselves. By paying attention to the previous peaks and troughs of the TTRP, it gives you a better idea of where strong resistance and support is likely to occur, essentially giving you a better range to trade within. You'll also notice that when the current TTRP breaks a significant enough number of previous peaks and troughs of the TTRP it's a more definitive conviction of whether the trend is to continue or change direction. As the peaks and troughs start to occur closer and closer in price in relation to each other, it indicates a tightening in the price action. Tightening of the price action is often an indication that there's going to be a significant continuation of the current trend or a significant change in trend direction once the current TTRP breaks a significant enough number of previous peaks and troughs that were occurring close together. When the TTRP breaks above enough previous peaks and troughs, the price is much more likely to have a significant breakout upward. When the TTRP breaks below enough previous peaks and troughs, the price is much more likely to have a significant breakdown downward. When either happens, I use the prices of previous peaks and troughs that are even further back in price history that the current TTRP has yet to break as my targets to take profit because that's where support/resistance is most likely to occur next. It makes it much easier to gauge the range in which price is likely to travel, giving you a much better idea of what kind of profit is likely when you are to take a trade and giving you a much better idea of when a good time to get in or out is.

And just to be clear, I define a "peak" as "current price is below the previous bar's price, while the price of two bars ago is also below the previous bar's price". I define a "trough" as the exact opposite, "current bar's price is above the previous bar's price, while the price of two bars ago is also above the previous bar's price".

Another way it can be implemented is by using the TTRP as the price for a moving average, rather than using say, the close price. By using the TTRP as the price that the moving average uses to calculate the average, it smooths out the average somewhat and causes the average to be affected less by significant price fluctuations within each candle during situations where volatility is high. This also makes breaks of the given average by price more significant. And that's something else I should mention is that crossovers of the TTRP with an average are also significant price levels where support/resistance is more likely to occur. And the more confluence there is (the closer the price of each peak, trough, and crossover are in relation to each other), the stronger that area of price becomes support or resistance and the more significant a move in price is to occur when that area of support or resistance is broken.

I'm currently working on an indicator that will include more features using the TTRP, but for now, here's a basic indicator that can be used to show the raw TTRP as well as an average of the raw TTRP much like the basic Typical Price indicator provided by ThinkorSwim:

Code:
input TypicalTrueRangePriceAverageType = averageType.SIMPLE;
input TypicalTrueRangePriceAverageLength = 9;

def ttrp = if TrueRange(high, close, low) == high - close then hlc3 else if TrueRange(high, close, low) == high - close[1] then (high + close + close[1]) / 3 else (low + close + close[1]) / 3;
def ttrpavg = MovingAverage(TypicalTrueRangePriceAverageType, ttrp, TypicalTrueRangePriceAverageLength);

plot TypicalTrueRangePrice = ttrp;
plot TypicalTrueRangePriceAverage = ttrpavg;
 
Last edited:
You can implement it in many different ways. If you want to see the "raw" TTRP, simply add the following code beneath the code provided in the original post:

Code:
plot TypicalTrueRangePrice = ttrp;

One of the ways I like to implement the raw TTRP is by paying attention to the peaks and troughs shown on the chart of the TTRP. In my opinion, the peaks and troughs of the TTRP are more important resistance and support levels than the peaks and troughs of the candles themselves. By paying attention to the previous peaks and troughs of the TTRP, it gives you a better idea of where strong resistance and support is likely to occur, essentially giving you a better range to trade within. You'll also notice that when the current TTRP breaks a significant enough number of previous peaks and troughs of the TTRP it's a more definitive conviction of whether the trend is to continue or change direction. As the peaks and troughs start to occur closer and closer in price in relation to each other, it indicates a tightening in the price action. Tightening of the price action is often an indication that there's going to be a significant continuation of the current trend or a significant change in trend direction once the current TTRP breaks a significant enough number of previous peaks and troughs that were occurring close together. When the TTRP breaks above enough previous peaks and troughs, the price is much more likely to have a significant breakout upward. When the TTRP breaks below enough previous peaks and troughs, the price is much more likely to have a significant breakdown downward. When either happens, I use the prices of previous peaks and troughs that are even further back in price history that the current TTRP has yet to break as my targets to take profit because that's where support/resistance is most likely to occur next. It makes it much easier to gauge the range in which price is likely to travel, giving you a much better idea of what kind of profit is likely when you are to take a trade and giving you a much better idea of when a good time to get in or out is.

And just to be clear, I define a "peak" as "current price is below the previous bar's price, while the price of two bars ago is also below the previous bar's price". I define a "trough" as the exact opposite, "current bar's price is above the previous bar's price, while the price of two bars ago is also above the previous bar's price".

Another way it can be implemented is by using the TTRP as the price for a moving average, rather than using say, the close price. By using the TTRP as the price that the moving average uses to calculate the average, it smooths out the average somewhat and causes the average to be affected less by significant price fluctuations within each candle during situations where volatility is high. This also makes breaks of the given average by price more significant. And that's something else I should mention is that crossovers of the TTRP with an average are also significant price levels where support/resistance is more likely to occur. And the more confluence there is (the closer the price of each peak, trough, and crossover are in relation to each other), the stronger that area of price becomes support or resistance and the more significant a move in price is to occur when that area of support or resistance is broken.

I'm currently working on an indicator that will include more features using the TTRP, but for now, here's a basic indicator that can be used to show the raw TTRP as well as an average of the raw TTRP much like the basic Typical Price indicator provided by ThinkorSwim:

Code:
input TypicalTrueRangePriceAverageType = averageType.SIMPLE;
input TypicalTrueRangePriceAverageLength = 9;

def ttrp = if TrueRange(high, close, low) == high - close then hlc3 else if TrueRange(high, close, low) == high - close[1] then (high + close + close[1]) / 3 else (low + close + close[1]) / 3;
def ttrpavg = MovingAverage(TypicalTrueRangePriceAverageType, ttrp, TypicalTrueRangePriceAverageLength);

plot TypicalTrueRangePrice = ttrp;
plot TypicalTrueRangePriceAverage = ttrpavg;
Thanks for the explanation. Do I have the peaks/troughs correctly identified on the attached image?
Screenshot 2023-08-18 212115.jpg
 
Last edited by a moderator:
Thanks for the explanation. Do I have the peaks/troughs correctly identified on the attached image?

Precisely. There are many more peaks and troughs within that screenshot, but I'm sure you were intending to point out just a couple of the best examples. One thing I'd like to point out in the screenshot though, is the 6th red candle in from the left side of the screenshot. There are 2 peaks and 2 troughs right before that, 1 of those peaks (the one further to the left) and both of those troughs were all broken by the TTRP of that 6th red candle by that point. It's a perfect example of what I was talking about, about the tightening of price action and a break of peaks/troughs. That 6th red candle would have been the perfect indication to short that security and/or buy a PUT for that security. By the way, I really like the painting strategy you opted to use for the indicator, I never really considered using that painting strategy for it, but I think I actually like it better than a dynamic line connecting the TTRP of each candle. Well done!
 
Precisely. There are many more peaks and troughs within that screenshot, but I'm sure you were intending to point out just a couple of the best examples. One thing I'd like to point out in the screenshot though, is the 6th red candle in from the left side of the screenshot. There are 2 peaks and 2 troughs right before that, 1 of those peaks (the one further to the left) and both of those troughs were all broken by the TTRP of that 6th red candle by that point. It's a perfect example of what I was talking about, about the tightening of price action and a break of peaks/troughs. That 6th red candle would have been the perfect indication to short that security and/or buy a PUT for that security. By the way, I really like the painting strategy you opted to use for the indicator, I never really considered using that painting strategy for it, but I think I actually like it better than a dynamic line connecting the TTRP of each candle. Well done!
It would be great if an indicator/strategy could be made to signal when a peak/trough is formed and also signal when the "pivot" is crossed. Just like the example on this chart that you pointed out. I did not notice the "micro" peak/troughs in that area before you pointed them out. I will see if I can get something created, using Chat GPT. 🤞
 
Okay. So I can get vertical lines to plot however this is too busy for my taste.
I wanted candle colors, but it isn't working. I also attempted an signal at the point of a
"Trough"[1]being crossed below by the current TTRP and visa versa for the "Peak".
Working but not as planned.Maybe someone that actually knows how to code may help.

*Added a moving horizontal line price on the ttrp as well.

Code:
#TTRP by: Jman831
#V1
#08/19/23
#Signals attempt by METAL

plot ttrp1 = if TrueRange(high, close, low) == high - low then hlc3 else if TrueRange(high, close, low) == high - close[1] then (high + close + close[1]) / 3 else (low + close + close[1]) / 3;

def ttrp = if TrueRange(high, close, low) == high - low then hlc3 else if TrueRange(high, close, low) == high - close[1] then (high + close + close[1]) / 3 else (low + close + close[1]) / 3;

def isTrough = ttrp > ttrp[1] and ttrp[1] < ttrp[2];
def isPeak = ttrp < ttrp[1] and ttrp[1] > ttrp[2];

def currentCandleTtrp = if isTrough then high else if isPeak then low else ttrp;

#Candle Color (Not working)
plot signal = if isTrough then ttrp else Double.NaN;
signal.AssignValueColor(if isTrough then Color.PINK else Color.CURRENT);

plot peakSignal = if isPeak then ttrp else Double.NaN;
peakSignal.AssignValueColor(if isPeak then Color.WHITE else Color.CURRENT);

AddVerticalLine(isTrough, "Trough", Color.yellow);
AddVerticalLine(isPeak, "Peak", Color.WHITE);

#Crosses below Trough low and Above Peak High (Not working properly)
def TroughL = if isTrough then ttrp[1] else TroughL[1];
def PeakH = if isPeak then ttrp[1] else PeakH[1];

def crossedBelowTrough = isPeak and currentCandleTtrp < TroughL[1];
def crossedAbovePeak = isTrough and currentCandleTtrp > PeakH[1];

plot UpArrow = if crossedBelowTrough then low - 2 * TickSize() else Double.NaN;
plot DownArrow = if crossedAbovePeak then high + 2 * TickSize() else Double.NaN;

UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetDefaultColor(Color.GREEN);

DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownArrow.SetDefaultColor(Color.RED);

# Horizontal Price Line
plot priceLine = highestAll(if isNaN(ttrp[-1])
then if high - low(period = AggregationPeriod.day) then hlc3 else double.nan
else Double.NaN);

priceLine.SetPaintingStrategy(PaintingStrategy.line);
priceLine.SetLineWeight(1);
priceLine.SetDefaultColor(CreateColor(50, 250, 150));
priceLine.HideTitle();

I can probably figure this out for you at some point, but I've been focusing more on a few other metrics to consider. What I'd like to do is create a feature where the length is adjustable that averages the price of X amount of previous peaks, where X is the length you choose as well as the same for troughs, an average of so many previous trough prices. The goal would be to essentially define a range to trade within with those two metrics, the average of peak prices and the average of trough prices. Unfortunately, I'm having a hard time figuring out a way to implement that. Refer to my other post in the Questions forum:
Thread 'How to get the offset value of the first of the last so many times a condition occurred?' https://usethinkscript.com/threads/...ast-so-many-times-a-condition-occurred.16392/
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
427 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top