I need to read a number of previous days bars for the same time period. For example, all the 9:30 bars on a 5 minutes chart for the past 20 days, then all 9:35 bars, then all 9:40 bars...
The goal is to calculate volume averages for specific time periods for $TVOL so that I can see where actual trading volumes stand relative to the averages at any given point of the day.
So far the only time functions I've found are getPreviousTradingDay() and getFirstBarIndexOfDay() but those don't let me access bars for a specific date and time, just the first bar for the previous or next day.
One way to work around this is to count the number of bars in the chart for the previous day (which is a complete day for sure) and then work with bars offsets to move around days. But then again, how do I know what's the last bar index for the previous day?
// This gives the first bar
var startBar = getFirstBarIndexOfDay(getPreviousTradingDay());
// Get the last bar, how to do this? no getLastBarIndexOfDay()...
//var endBar = getLastBarIndexOfDay(getPreviousTradingDay());
var BarsInOneDay = endBar - startBar;
var acc = 0;
for( i = 1; i <= 5; i++ ) {
// get all bars for the same period i days ago
acc += close(-BarsInOneDay*i);
}
// Return time-specific MA
return(acc/5);
The goal is to calculate volume averages for specific time periods for $TVOL so that I can see where actual trading volumes stand relative to the averages at any given point of the day.
So far the only time functions I've found are getPreviousTradingDay() and getFirstBarIndexOfDay() but those don't let me access bars for a specific date and time, just the first bar for the previous or next day.
One way to work around this is to count the number of bars in the chart for the previous day (which is a complete day for sure) and then work with bars offsets to move around days. But then again, how do I know what's the last bar index for the previous day?
// This gives the first bar
var startBar = getFirstBarIndexOfDay(getPreviousTradingDay());
// Get the last bar, how to do this? no getLastBarIndexOfDay()...
//var endBar = getLastBarIndexOfDay(getPreviousTradingDay());
var BarsInOneDay = endBar - startBar;
var acc = 0;
for( i = 1; i <= 5; i++ ) {
// get all bars for the same period i days ago
acc += close(-BarsInOneDay*i);
}
// Return time-specific MA
return(acc/5);
Comment