Percent change first bar of regular session


Category:
0
0

Hi Pete,

How would you write a scan showing stocks with a minimum gain/loss of 0.50% after the initial 5 min from the previous day’s close?

Thanks again!

Example: MSFT closed yesterday (9/16) on the 5-min at 305.24 while it closed today (9/17) after the initial 5-min at 303.05 for a loss of -0.72% so it would appear on the scan.

Marked as spam
Posted by (Questions: 20, Answers: 27)
Asked on September 17, 2021 9:45 pm
129 views
0
Private answer

The first assumption is that you do not intend to run this scan during the last few seconds of the first 5 min candle. Which would be required if we were not careful to design the code so that it carries the value forward through the rest of the trading session. You did not include such details in your request so I had to consider how the vast majority of our viewers would be most likely to run this scan.

The time frame for this scan is entirely up to you. The code does not need to know what time frame is being applied to the Study Filter. I have included a user input to adjust the percent threshold without modifying the logic or structure of the code. Notice there are two separate signals in this scan. One for each direction. This allows our viewers to select whichever direction they want to run this scan.

This scan will only work as requested if extended hours session is excluded from the Study Filter.

input percentThreshold = 0.5;
def newDay = GetDay() <> GetDay()[1];
def trackPercentChange = if newDay then 100 * (close / close[1] - 1) else trackPercentChange[1];
# use this to scan for percent change greater than threshold
plot scan = trackPercentChange > percentThreshold;
# use this to scan for percent change less than threshold
#plot scan = trackPercentChange < -percentThreshold;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 18, 2021 11:16 am
0
Thanks Pete! I ran this scan under the 5-min time frame. AMZN & TGT appeared but they didn't fit the greater than the threshold so would you might know why they showed up?
( at September 18, 2021 8:56 pm)
0
Sorry about that. I have updated the code to fix that. The original solution I provided was converting the percent threshold to 0.05%. The updated version above will use the value of 0.5% instead.
( at September 18, 2021 10:00 pm)
0
This works now! You're the best Pete!
( at September 19, 2021 12:12 pm)
0
Hi Pete, Is there a way to tweak the percentthreshold for between two numbers? Thanks again!
( at November 14, 2021 12:16 pm)
0
plot scan = trackPercentChange > 5 and trackPercentChange < 10;
( at November 14, 2021 12:56 pm)
0
Lastly, is this formula based on 15-Min - previous day's close because the pct is different if it's between initial 15 min - previous day's final 15 min. I'm asking because I'm getting a different pct for the results from the previous day's close which is what I'm looking for.
( at November 14, 2021 2:11 pm)
0
The code does not know what time frame you have selected. Doesn't matter what time frame you select. The code looks at the percent change between the last bar of the previous regular session and the first bar of the next day's regular session. You must exclude extended hours data for this to work.
( at November 14, 2021 2:23 pm)
0
Hi Pete, Is there a way to add closed above/below the high/low of the first candle to this scan?
( at May 28, 2022 2:37 pm)
0
Now that I see which question you were referring to I see that there is nothing in this code which can be used to alert when price crosses and closes beyond any specific level. In fact this code does not compute any such levels at all. Seems that your request actually has nothing to do with what this solution is designed to perform. So the answer is no, there is no way to modify this solution to find stocks crossing above or below the high or low of the first candle. I suggest you search this forum for the term "opening range", in which you will find many examples have already been posted.
( at May 28, 2022 3:39 pm)