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.

Thanks for the detailed explanation. So is the original expression equivalent to:
Code:
``Highest(high, 2 * kijun_period)[kijun_period]``

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.

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

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

test2 - highest offset

Not the exact question you're looking for?

87k+ Posts
365 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?