I recently wrote a bit of code which purpose is to calculate Intraday-Turnover no matter what resolution you're looking at. The results:
The code calculates the intraday value of all contracts which was sold and resets until the next day, and it seems to work fine.
Out of curiosity and learning, I wanted to make an array which stored the Close of the last bar of each day, no matter the resolution. I figured that since I've got some code that already figures out when the next day comes, this shouldn't be a problem.
And now the results are completely different. As soon as I try to assign any variable to "Close[currentbar]", the rest of my code stop working properly. How come this is? It's driving me nuts. I know I can use different data series, but for this experiment I'm trying to fit it into the same.
when you index a reserved word or variable to get the value from X bars back the values start from the current bar and go up. Currentbar = 0, 1 = the bar on the left from the currentbar etc.
With Close[CurrentBar] you are likely trying to look at a bar that is not even accessible. Assume you are at CurrentBar = 100, with Close you try to access the 100th bar left from the current bar. Which means you'd need 101 bars on the chart, but only have 100 at current bar 100.
Long story short you have to use Close to get the current close at the moment of the code calculation.
The following user says Thank You to ABCTG for this post: