Scanner is using older candles than what is intended

Rose Investing

New member
Hello everyone, right now I am working on some code that is to be utilized in a scanner. The code will identify the premarket high and then will plot true if during the trading session (I'm just working with stocks so lets assume 9:30 - 16:00 EST) the stock crosses above the premarket high. The code works great and does everything I want it to, during the premarket it identifies the high, once the stock crosses the premarket high during trading hours then the plot turns to true and it stays at true until the code detects that its a new day and then resets back to false. Here is the code:

Code:
#define boolean values for trading hours and pre market
def inSession = secondsFromTime(0930) >= 0 and secondsTillTime(1600) > 0;
def PM = secondsFromTime(0000) >= 0 and secondsTillTime(0930) > 0;

def day = getDay();

#defining the premarket high for the day
def PMHigh = if day != day[1] and inSession #this essentially means there was no PM data
             then double.NAN
             else if day != day[1] #reseting for if its a new day
                  then high
                  else if PM
                       then if high > PMHigh[1]
                            then high
                            else PMHigh[1]
                       else PMHigh[1];

#defining the premarket high break(boolean value)
def PMHighBreak = if day != day[1] #setting it to reset daily
                  then no
                  else if inSession and high > PMHigh
                       then yes
                       else PMHighBreak[1];
                
plot BrokePreMarketHighs = PMHighBreak;

Now the problem here isn't in the study, its when I utilize it as a scanner. If I run this scan in the morning my first thought was that no tickers should appear in the scan, however that's not the case. It seems that the scanner will actually pick up stocks who's MOST RECENT CANDLE has a true value for the plot "BrokePreMarketHighs". This means a stock could have broken pre market highs yesterday, but at 16:05 it printed its most recent candle and just hasn't done any transactions on this new day in order for the plot to reset (it resets daily). So right now my scanner is picking up a bunch of stocks in the premarket that haven't done any volume since the afterhours of the previous day when its "BrokePreMarketHighs" plot value was true.

Does anyone know any way around this? how can the most recent candle know what time it is regardless of the chart? I assume that's the route I'll need to take to fix this but open to any alternatives as well. Let me know if you need any more information or want me to explain anything. Thanks
 
Last edited:

Similar threads

Top