I'm having trouble with a chart comparing volume to the average of the past 4 days, for the same bar of the day.
The code below is working without extended hours enabled but I'm trying to make it work with the extended session enabled. I've tried including the extended session bars using SPY as a test. Since SPY displays in ToS 24 hours, I set the length to 288 (24 hours * 12 five min bars/hr) but it's not calculating the average as expected.
I'd rather the extended market bars were ignored completely - different tickers have more/less extended session bars. I'm not sure if there's a way to skip those volume bars with the indexing operator ( [ ] ).
Any ideas would be greatly appreciated.
The code below is working without extended hours enabled but I'm trying to make it work with the extended session enabled. I've tried including the extended session bars using SPY as a test. Since SPY displays in ToS 24 hours, I set the length to 288 (24 hours * 12 five min bars/hr) but it's not calculating the average as expected.
I'd rather the extended market bars were ignored completely - different tickers have more/less extended session bars. I'm not sure if there's a way to skip those volume bars with the indexing operator ( [ ] ).
Any ideas would be greatly appreciated.
Code:
declare lower;
declare zerobase;
# each day's 6.5 hour session has (78) 5-minute bars
def length = 78;
input paintBars = no;
def isGreen = volume > ((volume[length]+volume[length*2]+volume[length*3]+volume[length*4])/4);
def isRed = volume < ((volume[length]+volume[length*2]+volume[length*3]+volume[length*4])/4);
plot Vol = volume;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Green", Color.DARK_GREEN);
Vol.DefineColor("Red", Color.DARK_RED);
Vol.AssignValueColor(if isGreen then Vol.Color("Green") else if isRed then Vol.Color("Red") else Color.LIGHT_GRAY);
DefineGlobalColor("Green", Color.DARK_GREEN);
DefineGlobalColor("Red", Color.DARK_RED);
AssignPriceColor(if !paintBars then Color.CURRENT else if isGreen then GlobalColor("Green") else if isRed then GlobalColor("Red") else Color.LIGHT_GRAY);