Crossing event anytime during extended hours


Category:
-1
0

Hi Pete, this is my first time posting though I’ve been an avid reader of your site for a couple years now. It is a credit to the wealth of knowledge on this resource that I’ve always found an answer to previous coding obstacles by searching through the forums without having to raise a new question.

Hoping you can help with something I can’t seem to resolve on my own: Creating a scan that will list all stocks with a MACD histogram crossover (-ve to +ve) during extended hours (1600 to 930 EST).

When I combine the stock MACD Histogram Crossover filter within TOS with your own ‘ScanPeriod’ code I am only seeing results from the most recent bar (30 Minute Timeframe), whereas I would like to create a snapshot that stops updating at 930 which displays ALL extended hour crossovers.

Code attached.

Thanks in advance!

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on November 9, 2021 9:56 pm
86 views
0
Private answer

I updated the title of the question to more clearly express what I believe you have requested. This should make it easier for other viewers searching for a similar solution to quickly locate this using the search function.

I think I understand the request but I'm not entirely sure. So I will restate this in my own terms.

You would like the scan to return a list of stocks that have had at least one positive MACD Histogram crossover at any time within the extended hours session. And you would like to be able to run that scan at any time during the current trading session. Which means for every stock that has a crossing event, lock that signal in and hold that for the rest of the current day's trading sessions.

This solution requires some extremely advanced code. Might seem simple to the average trader. But the code required to do this took me years to comprehend. (and even more time to learn how to compress it into just a handful of lines of code). Here is the solution I described above:

input regularSessionStartTime = 930;
input regularSessionEndTime = 1600;
def regularSessionHours = SecondsFromTime(regularSessionStartTime) >= 0 and SecondsTillTime(regularSessionEndTime) > 0;
def extendedSessionHours = !regularSessionHours;
def signal = MACDHistogramCrossover("crossing type" = "Negative to Positive");
rec trackSignal = if extendedSessionHours and regularSessionHours[1] then 0 else if extendedSessionHours and signal then 1 else trackSignal[1];
plot scan = trackSignal;

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on November 10, 2021 8:22 am
0
Pete: This is exactly what I was looking for! You understood and restated my request perfectly, and the result works just as planned; especially with locking and holding the signal as a static snapshot for the rest of the trading day. Thank you for making this challenging code available so quickly, I appreciate how tricky this must have been. Donation on the way to respect your time...... thanks Pete!
( at November 10, 2021 9:03 am)
0
Thanks in advance for your voluntary contribution. We don't refer to those as "donations" because Hahn-Tech, LLC is a for-profit company and we cannot accept "donations". Glad I was able to provide the solution you requested.
( at November 10, 2021 9:35 am)