I am working on a scan that would average volume of each bar during regular trading hours over a set period of days (currently set to 3) and compare it to the current bars volume. The intent is to use it on the 30 min period, though it could work on other intraday periods (except ones that do not divide evenly into a 6.5hr trading day). The scan would trigger when the current bars volume is greater than some multiple of the average (right now its set to 2 times). This is the scan as it currently is.
I also have a study with the same logic that I have been using to tune the scan and make sure it will function as desired.
Currently the study works as i desire, but the scan does not work consistently. The problem is that it does not always provide accurate results when compared to the study. My guess is that this issue is due to the scanners inability to pull all the data needed to accurately sum the volume though I'm not sure if that is the cause.
I would appreciate any advise on how to resolve the issue or change the script to accomplish the goal.
Code:
# 1. Define the RTH condition.
def isRTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() < RegularTradingEnd(GetYYYYMMDD());
# 2. Define the time condition by counting unique trading days.
def isNewDay = GetDay() != GetDay()[1];
def dayNumber = CompoundValue(1, if isNewDay then dayNumber[1] + 1 else dayNumber[1], 1);
def lastDayNumber = HighestAll(dayNumber);
def isWithin3Days = dayNumber > lastDayNumber - 3;
# 3. Combine the conditions to identify the target bars.
def finalCondition = isRTH and isWithin3Days;
# 4. Sum the volume of only the target bars.
def totalVolume = TotalSum(if finalCondition then volume else 0);
def numberOfBarsSummed = TotalSum(if finalCondition then 1 else 0);
def AvgVol = totalVolume/numberOfBarsSummed;
plot Scan = isRTH and volume > AvgVol * 2;
I also have a study with the same logic that I have been using to tune the scan and make sure it will function as desired.
Code:
# 1. Define the RTH condition.
def isRTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() < RegularTradingEnd(GetYYYYMMDD());
# 2. Define the time condition by counting unique trading days.
def isNewDay = GetDay() != GetDay()[1];
def dayNumber = CompoundValue(1, if isNewDay then dayNumber[1] + 1 else dayNumber[1], 1);
def lastDayNumber = HighestAll(dayNumber);
def isWithin3Days = dayNumber > lastDayNumber - 3;
# 3. Combine the conditions to identify the target bars.
def finalCondition = isRTH and isWithin3Days;
# 4. Sum the volume of only the target bars.
def totalVolume = TotalSum(if finalCondition then volume else 0);
def numberOfBarsSummed = TotalSum(if finalCondition then 1 else 0);
def AvgVol = totalVolume/numberOfBarsSummed;
#debug----
addLabel (yes,"number of bars " + numberOfBarsSummed,Color.white);
addLabel (yes,"Avg Bar Volume " + AvgVol,Color.white);
AddLabel(yes, "3-Day RTH Volume: " + totalVolume, Color.WHITE);
#output----
# B. Plot an arrow on each bar being included in the sum.
plot highBar_Arrow = isRTH and volume > AvgVol * 2;
highBar_Arrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
highBar_Arrow.SetDefaultColor(Color.WHITE);
Currently the study works as i desire, but the scan does not work consistently. The problem is that it does not always provide accurate results when compared to the study. My guess is that this issue is due to the scanners inability to pull all the data needed to accurately sum the volume though I'm not sure if that is the cause.
I would appreciate any advise on how to resolve the issue or change the script to accomplish the goal.