Could someone explain these Thinkscript statements?

cay7man

Member
1. def peak = high > Highest(high[1], LeftBarsThreshold) and high >= Highest(high[-RightBarsThreshold], RightBarsThreshold);
plot peakBoolean = peak;

Assuming LeftBarsThreshold is 5, Highest(high[1], LeftBarsThreshold) is Highest of 5 bars from 1 bar ago?
Assuming RightBarsThreshold is 5, Highest(high[-RightBarsThreshold], RightBarsThreshold) is Highest of 5 bars from 5 bars ago? I'm bit confused with the use of negative sign in front of bar index. Why not use Highest(high[5],RightBarsThreshold)?

2. def peakValue = if peak then high else peakValue[1];

What will be the value of peakValue[1] when the the above statement was executed for the first time? Does the array (peakValue) grow as each bar
is processed?

TY!
 
Solution
1. def peak = high > Highest(high[1], LeftBarsThreshold) and high >= Highest(high[-RightBarsThreshold], RightBarsThreshold);
plot peakBoolean = peak;

Assuming LeftBarsThreshold is 5, Highest(high[1], LeftBarsThreshold) is Highest of 5 bars from 1 bar ago?
Assuming RightBarsThreshold is 5, Highest(high[-RightBarsThreshold], RightBarsThreshold) is Highest of 5 bars from 5 bars ago? I'm bit confused with the use of negative sign in front of bar index. Why not use Highest(high[5],RightBarsThreshold)?

2. def peakValue = if peak then high else peakValue[1];

What will be the value of peakValue[1] when the the above statement was executed for the first time? Does the array (peakValue) grow as each bar
is processed?

TY!

Assuming...
1. def peak = high > Highest(high[1], LeftBarsThreshold) and high >= Highest(high[-RightBarsThreshold], RightBarsThreshold);
plot peakBoolean = peak;

Assuming LeftBarsThreshold is 5, Highest(high[1], LeftBarsThreshold) is Highest of 5 bars from 1 bar ago?
Assuming RightBarsThreshold is 5, Highest(high[-RightBarsThreshold], RightBarsThreshold) is Highest of 5 bars from 5 bars ago? I'm bit confused with the use of negative sign in front of bar index. Why not use Highest(high[5],RightBarsThreshold)?

2. def peakValue = if peak then high else peakValue[1];

What will be the value of peakValue[1] when the the above statement was executed for the first time? Does the array (peakValue) grow as each bar
is processed?

TY!

Assuming LeftBarsThreshold is 5, Highest(high[1], LeftBarsThreshold) is Highest of 5 bars from 1 bar ago?
yes

Assuming RightBarsThreshold is 5, Highest(high[-RightBarsThreshold], RightBarsThreshold) is Highest of 5 bars from 5 bars ago?
no

a negative offset, means look at future bars. this means,
high[-RightBarsThreshold]
move to the right 5 bars.

Highest( high[-5] , 5 )
this means, Find the highest value for high over 5 bars.
The -5 offset on high, means to change the starting bar for highest(). to move 5 bars to the future , the right.
then look left and find the highest of 5 bars.

this range won't include the current bar.
high[1] , means to move 1 bar left.
highest( high, 1) , means to find the highest value over a range of 1 bar, just the current bar.


https://tlc.thinkorswim.com/center/...dvanced/Chapter-12---Past-Offset-and-Prefetch

----------

2. def peakValue = if peak then high else peakValue[1];


What will be the value of peakValue[1] when the the above statement was executed for the first time?
0 or na

Does the array (peakValue) grow as each bar is processed?
no

when peak is true, peakvalue will be = to the high.
when peak is false, peakValue will be set with a value from The 2nd half of the if then statement, peakValue[1] , which is the value of the previous bar.
So when a peak happens, the high is read. then that value is saved in future bars, until a new peak is found.

If this is plotted it will be several horizontal lines, extending from peaks.
plot z = peakValue;
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
401 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