Starting data pull in scan at a specific time (0700 EST)


Category:
0
0

Good evening Pete,

I’ve been getting noise from the previous day’s final volume bars (and sometimes after market too) in the volume scan I’ve been running. So now I’m trying to create a scan that only starts aggregating data at 0700 each day, ignoring the previous day’s bars. I think I’m on the right track now but am having problems trying to figure out how to fit in the boolean portion. The def isopen line is the new stuff. Any help would be much appreciated.

# Unusual Volume Scan

def agg = aggregationperiod.five_min;
def price = volume (period = agg);

def isopen = if secondsFromTime(0700)>= 0 and secondstillTime(1600)>= 0 then 1 else 0;

def percent1 = 300;
def percent2 = 1500;
def length = 500;
def avg = average(price, length)[1];
def chg = 100*(price/avg -1);

def bullsignal = chg between percent1 and percent2;

#plot bullscan = bullsignal;
plot bullScan = Sum(bullSignal, 3);
#plot bearScan = Sum(bearishSignal, 10);

Sincerely,

CW

Marked as spam
Posted by (Questions: 2, Answers: 2)
Asked on May 20, 2020 6:09 pm
117 views
0
Private answer

Your code uses a secondary aggregation. These are not supported for scans so they code will fail you try to use this on anything but a five min time frame. The variable you created to define the time span is not used anywhere in the code. So we have many problems to address long before we get down to the part you are asking to solve. Which is a boolean condition to create the scan filter. However you did not explain what that condition SHOULD be and your code provides zero hints as to what that true/false condition should be.

Dead in the water here.

Edit: After receiving more details in the comment section below I am providing a link to a previous post that provides code used to control the times when a scan is able to produce results.

https://www.hahn-tech.com/ans/scan-within-a-specific-hour-time-range/

If you had searched for this solution before posting this question you should have run across that post. That code will only impact the times in which a scan is able to produce results. The code is meant to be added as a separate Study Filter of your scan. It does NOT control the time span during which the signal is computed. So if you have some computation that needs to be restricted to a specific span of time, the code from that link will not impact that at all.

If your scan includes some metric that needs to be computed only within a specified period of time, this code can be incorporated into existing code. The variable named scanPeriod can be converted from a plot to a def. After this you can use that scanPeriod variable to restrict the time span for which various metrics are computed.

Since your example code did not include such metrics I do not have a specific solution for you.

From your question:

So now I’m trying to create a scan that only starts aggregating data at 0700 each day, ignoring the previous day’s bars

You seem to indicate that you have such a metric you would like to restrict in this way, however I did not find anything of that kind in your code.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on May 21, 2020 7:27 am
0
My apologies Pete, I tried to cover it all in the first question. For the secondary aggregation, I only use it on a five minute frame. It's more of a peace of mind thing than anything else because sometimes it seems like I get wonky results using the stock 5m scan. It might be redundant, but it helps with the peace of mind when I'm scanning. For the def isopen variable I should have been more clear. I was first wondering/making sure that is the correct variable to define the times to scan (0700 to 1600). Basically making sure I was at least on the right track. If I was, then the condition should be that if it is between 0700 and 1600, the scan is on/will bring results, if it is not between those time frames, then no results should be brought. And that's where I'm running into trouble with implementing a boolean condition. I think I could also just use def isopen = secondsFromTime(0700)>= 0 and secondstillTime(1600) >= 0, then put that down in the plot bullScan = Sum(bullSignal, 3) AND isopen; to get the same results? But I'm not 100% sure on that
( at May 21, 2020 8:36 am)
0
I have updated my answer to provide all the details I can at this time. Seems to me we might still need more details from you. But if this solve the issue then you are good to go.
( at May 21, 2020 11:43 am)
0
Thanks for the followup questions, Pete. It has helped me drill down on where I need to go. Originally, I thought if I restricted the scan until 0700 it wouldn't pull bars from the previous day, but after your last answer it still would. So I retooled the scan and it seems to work now. I appreciate the help!
( at May 22, 2020 9:24 am)