Thanks for this great script, very useful.
One question:
Can you or someone else explain what the following line does? (It is a question that has more to do with thinkScript basics, but wasn't able to find a similar example in TOS thinkscript pages to understand it)
# average of cumulative volume at this time of day for the last 10 trading days
def avgCumVolume = (cumVolume[(bpd*1)] + cumVolume[(bpd*2)] + cumVolume[(bpd*3)] + cumVolume[(bpd*4)] + cumVolume[(bpd*5)] + cumVolume[(bpd*6)] + cumVolume[(bpd*7)] + cumVolume[(bpd*8)] + cumVolume[(bpd*9)] + cumVolume[(bpd*10)]) / 10;
I understand -thanks to the comment- what it is supposed to do. But I don't get where is the cumVolume coming from.
Because when the cumVolume was declared a couple of lines above, it was storing the cumulative volume for the current day.
But in this line you can access the previous days' volume? How come? (no pun intended )
The index at the end of cumVolume, between the brackets [], defines how many candles back we are looking. In this case we use the bpd variable, which tells us how many bars there are in a day, and we're multiplying that by the number of days to look back. cumVolume with no index is equivalent to [0] and represents now. cumVolume[1] is the previous candle. cumVolume[bpd] is the candle at this time on the previous trading day.
That line retrieves the volume at that time of day for each of the previous 10 trading days and divides by 10 to get the average. That tells us what is "normal" volume by this time of day. Then we calculate today's volume so far as a % of that "normal".
Last edited: