How to find yesterday last barindex number through array? because i have calculate pivot array value of yesterday Close. i had use normally ref(array,shift), which is today intraday pivot value each bar changing. so i had use another option Lastvalue(barindex()) which is also pivot value each bar changing. if find yesterday barindex value, i could Constant of barindex by intraday. please help.
@Ganesan I didn't have time to look at your code and am sleep deprived, but I think you asked for
If that is all you are looking for then perhaps this might help.
dn = Day();
BI = BarIndex();
newDay = dn != Ref( dn, -1 ); // New Day, not needed just here for clarification/illustration
LastBarYesterday = dn != Ref( dn, 1 ); // Yesterday's last bar (you are using intra-day data)
LastBarYesterdayBI = ValueWhen( LastBarYesterday, BI ); // value of the Bar Index on that bar
Meanwhile please help the code for the above my image file (algorithm chart) which need to movable GFX Axes scales.`
for( j = 1; j < 9; j++)
{
num1 = num1 + i;
}
i++;
}
Hello, i had insert the LastBarYesterdayBI, but showing "Error9. Array subscript has to be a number", then i had add lastvalue function, which is more slowing the chart. what is the mistake i had?
see the image
Everything inside the square brackets [] should be a number and NOT an array!
For example:
Close[BarCount-1]; // OK
Close[BarIndex()]; // WRONG
but
Close[LastValue(BarIndex())]; // OK
This is OK since you are using a function to retrieve a number to be used as an index in the [ ].
If you look at the functions documentation, you can clearly see the return type.
SYNTAX: LastValue(ARRAY, lastmode = True ) RETURNS: NUMBER
In your code, you are using an array that is returned from a call to ValueWhen() that you are treating as an array subscript.
Check the function documentation again and try to figure out what value you actually need to use.
Adding some exploration columns with all the arrays used in your logic is always a good step to debug your code.
Before going forward, I suggest you to study until you completely understand the first document that was linked by @codejunkie.
It is vital to use AFL and there are no shortcuts!
Learn how to use array functions, like @portfoliobuilder already showed you, since in many cases there is no need for the loop (try his sample code and see if you are able to explain precisely how it works).
Only when there is no alternative you need to use loops over the bars, but in this case, it is imperative to fully comprehend how to access appropriately any element using the array subscript.
@Ganesan your exploration (and the documentation) shows that
LastBarYesterdayBI = ValueWhen( LastBarYesterday, BI );
LastBarYesterdayBI is an ARRAY.
So this line, as expected, gives an error.....
Pvt[i] = Pvt[LastBarYesterdayBI];
You NEED to use a NUMBER as an array subscript and be sure that this number is in the 0 .. BarCount-1 range.
Honestly, I don't know how to say that in such a way so you'll get it... (even without taking into account the rest of the code that needs to be significantly revised ...)
Again, I suggest to reread and study the linked docs.