Using the highest high

Cribbage

New member
This is confusing me more than it feels like it should, from the accumulationdistribution study on ToS:

length = 4
def range = Highest(high, length) - Lowest(low, length);
plot RangeRatio = range / range[length];

To me this is saying "highest high of the last 4 - lowest low of the last 4" is being divided by the same thing, meaning the outcome would always be 1. Where am I misunderstanding this?

Which brings me to another point: Is there a glossary of commands on this site? I would love it if there were a glossary section where different ThinkScript could be explained more thoroughly in plainspeak. I found the TOS learning center to be more confusing than helpful on the "Highest()" command.
 

rad14733

Well-known member
VIP
@Cribbage We don't necessarily "need" a Glossary because we have the Thinkscript Learning Center for that... No need reinventing the wheel here...

As for the code you posted...

Ruby:
length = 4
def range = Highest(high, length) - Lowest(low, length);
plot RangeRatio = range / range[length];

First, notice how I used code tags which you could enter manually, or use the </> icon to post a block of Thinkscript code for better presentation... Most members use the Ruby syntax style works best for Thinkscript...

What the code does is to find the highest high and lowest low values within length bars, 4 in this case, and then divides that result, range, by by the range length bars ago... So it takes the highest high within the last 4 bars and subtracts the lowest low within the last 4 bars and then divides that by what the range value was 4 bars ago... That's what it does and that's how it reads...

Remember, Thinkscript is considered a self-documenting scripting language, meaning that it explains itself and thus requiring less documentation... And that is why it is better to use fully descriptive variable names rather than short cryptic variable names... That is why you see the variable "range" instead of "r", "RangeRatio" instead of "RR", "length" instead of "l", etc...

I hope this helps answer your question...
 

MerryDay

Well-known member
VIP
@Cribbage I asked myself many of the same questions. Like you, I delved into many of the TOS indicators and almost all the custom studies on this forum in order to understand ThinkScript. And sometimes it left me confused.
What helped me was the AddChartBubble. This allows the display of the values of variables by candle. By seeing the results of the calculations, I could get an understanding of what the functions were doing. Sometimes I had to do MANY chart bubbles in MANY studies to internalize the knowledge. However, it does get easier. TOS is standardized in its methodology. So learning subsequent functions becomes progressively easier.
nBHT2zN.png

A sample syntax for AddChartBubble is at the bottom of this script:
Ruby:
def data = if close > close[1] then close - Min(close[1], low) else if close < close[1] then close - Max(close[1], high) else 0;

def AD = TotalSum(data);
def AccDist = (AD - lowestall(AD)) /(highestall(AD) - lowestall(AD));
def stoch = StochasticSlow("over bought" = 100, "over sold" = 0, "k period" = 14, "d period" = 1).SlowD;
def SlowD =  (stoch - lowestall(stoch)) /(highestall(stoch) - lowestall(stoch));

input length = 4;
def range = Highest(high, length) - Lowest(low, length);
plot RangeRatio = range / range[length];

AddChartBubble(AccDist crosses above SlowD, close, "RangeRatio: " +RangeRatio +" | " +"Range: " +Range +" | " +"range[length]: " +range[length] , Color.violet, no);
To learn more about AddChartBubble:
https://usethinkscript.com/resources/thinkscript-addchartbubble-add-and-customize-chart-bubbles.13/
HTH
 

Cribbage

New member
Awesome, thanks for the advice everyone. On the basis of the glossary, I know about the Learning Center on TOS, my point is look at the example they used for highest high (below). Rad's explanation was a dozen times easier to understand, and now if anyone else has a question about using the command its listed here. In any case - Thank you for the explanations - Appreciate it.

Example
Code:
input length = 20;

plot LowerBand = Lowest(low[1], length);
plot UpperBand = Highest(high[1], length);
plot MiddleBand = (LowerBand + UpperBand) / 2;

The plots in the example illustrate the Donchian Channels system where the Lower Band and the Upper Band are calculated as the minimum low and maximum high for the previous length bars. Note that the low and high for the current bar are left out of account. In order to implement this approach the [1] index is applied to the corresponding parameters.
 

Cribbage

New member
Just coming to correct myself, reading through MerryDay's post - The link to the Code Reference center is what I was referring to in my request, I was just calling it a glossary. This is awesome. Thanks again!
 

halcyonguy

Member
VIP
@MerryDay
@Cribbage
i agree, most of the time, TD's code examples left me more confused.

here is my version of using bubbles to display values. i use \n to force the following text, on a new line.

Code:
AddChartBubble(AccDist crosses above SlowD, close, "RangeRatio: " +
RangeRatio + "\n" +"Range: " + Range + 
"\n" +"range[length]: " + range[length] , Color.violet, no);
 
Last edited:

Similar threads

Top