Can this array thinkscript be simplified?

Zac

New member
Looking at the source for the Ichimoku cloud (built in study), I found this:
Ruby:
Highest(high[kijun_period], 2 * kijun_period)

Is this equivalent to:
Ruby:
Highest(high, 2 * kijun_period)
?
 
Solution
no, they are different

high , or high[0]
get the high from the current bar
offset is 0

i'm going to assign a value of 10 to help explain it. the [ ] number is an offset.
def kijun_period = 10;
high[kijun_period]
( same as high[10] )
when [ ] are used, it means go to another bar and read a value.
it is saying, go back 10 bars and read the value of high.


highest( high , 20 )
or highest( high[0] , 20 )
this means to start at the current bar then look back 20 bars and find the highest high


highest( high[10] , 20 )
by adding an offset to the price variable, it changes the starting point of where highest looks. instead of the current bar, some other bar.
high[10] means go back 10 bars, THEN look back 20 bars, from that bar, to find the...
no, they are different

high , or high[0]
get the high from the current bar
offset is 0

i'm going to assign a value of 10 to help explain it. the [ ] number is an offset.
def kijun_period = 10;
high[kijun_period]
( same as high[10] )
when [ ] are used, it means go to another bar and read a value.
it is saying, go back 10 bars and read the value of high.


highest( high , 20 )
or highest( high[0] , 20 )
this means to start at the current bar then look back 20 bars and find the highest high


highest( high[10] , 20 )
by adding an offset to the price variable, it changes the starting point of where highest looks. instead of the current bar, some other bar.
high[10] means go back 10 bars, THEN look back 20 bars, from that bar, to find the highest high.
 
Solution
Thanks for the detailed explanation. So is the original expression equivalent to:
Code:
Highest(high, 2 * kijun_period)[kijun_period]


yes, they are the same.


Ruby:
#
# good question.
# if i don't know what a formula is doing, i create some test formulas and display their values on the chart, in bubbles.

# simplify and rewrite the formulas, by replacing long variable names.

def bn = barnumber();
def x = 2;
def t1 = Highest( high[x] , 2 * x )[0];
def t2 = Highest( high[0] , 2 * x )[x];

# create a bubble to display the variable values on the chart.
#   i tend to adjust the vertical placement of objects, so they aren't touching the candles.
#   i use  "\n"  to force data after it, to be on a new line.

addchartbubble( 1, low*0.997,
bn + "  bar#\n" +
high + "  H\n" +
t1 + "  Hi[x]\n" +
t2 + " est[x]"
, color.yellow, no);
#


test bubbles. they show the same values, for 2 different formulas
1yugQEm.jpg



here are a couple of visuals that might help.
wether you start with an offset on a variable, or do an offset on the function, you end up covering the same range of bars.

test1 - high offset
OON5cV0.jpg



test2 - highest offset
EEsowp6.jpg
 

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
432 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