• Memorial Day Sale! Claim the biggest discount of the year with $50 off VIP using code MEM50. Sign up here.

Low High from United Traders scan?

ezrollin

Member
This is their indicator. It works really well. Is there any way to turn it into a scan in order to see stocks that are making new highs over and over?
I've tried before but it is too intensive for TD's servers.

Code:
input marketOpen = 830;
input marketClose = 1500;
input intraDaySpan = {Default "SameDay" , "OverNight"};
input numberOfDays = 1;
input numberOfYears = 0;
plot newhigh;           #I'm adding this for scans.   See the end


def okToPlot = GetLastDay() - numberOfDays <= GetDay() and GetLastYear() - numberOfYears <= GetYear() ;

def OpenCounter =  SecondsFromTime(marketOpen);
def CloseCounter = SecondsTillTime(marketClose);

def MarketHours = if OpenCounter >= 0 and CloseCounter >= 0 then 1 else 0;

def beforeMidnight = OpenCounter >= 0 and CloseCounter <= 0;
def afterMidnight = OpenCounter <= 0 and CloseCounter >= 0 ;

def Today ;
def hideChartBubbles ;
rec DailyHigh ;
rec DailyLow ;

switch (intraDaySpan) {
    case "SameDay":
    Today = if GetDay() != GetDay()[1] then 1 else 0;
    DailyHigh = if MarketHours then if high > DailyHigh[1] then high else DailyHigh[1] else high;
    DailyLow = if Today then low else if MarketHours then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = MarketHours;
    case "OverNight":
    Today = 0;
    DailyHigh = if beforeMidnight or afterMidnight then if high > DailyHigh[1] then high else DailyHigh[1] else  high;
    DailyLow = if beforeMidnight or afterMidnight then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = beforeMidnight or afterMidnight;
};

AddLabel(close > 0, Concat( "Dly High: " , DailyHigh), Color.GRAY);
AddLabel(close > 0, Concat( "Dly Low: " , DailyLow), Color.GRAY);
AddLabel(close > 0, Concat("Range: " , (DailyHigh - DailyLow) / TickSize()), Color.GRAY);
plot TodaysHigh = if okToPlot and MarketHours then DailyHigh else Double.NaN;
plot TodaysLow = if okToPlot and MarketHours then DailyLow else Double.NaN;
TodaysHigh.SetDefaultColor(Color.GREEN);
TodaysLow.SetDefaultColor(Color.RED);

AddChartBubble(DailyHigh > DailyHigh[1] and hideChartBubbles and okToPlot, DailyHigh, "Hi", color.GREEN, yes);

AddChartBubble(DailyLow < DailyLow[1] and hideChartBubbles and okToPlot, DailyLow, "Lo", color.RED, no);

Alert(DailyHigh > DailyHigh[1] and MarketHours, "New Hi", Alert.ONCE);

Alert(DailyLow < DailyLow[1] and MarketHours, "New Low", Alert.ONCE);


This is my scan:

Code:
if DailyHigh > DailyHigh[1] and MarketHours {
    newhigh = 1;
} else {
newhigh = 0;
}
 
Last edited by a moderator:
Solution
@ezrollin Per your request, I have converted the study you posted above into a scan. This is based on the underlying logic as contained in your study. I have configured this as a bullish scan. If you'd like to set this up as a bearish scan, just change the plot statement on the last line to

Code:
plot scan = bear;

I have tested both bullish as well as bearish scans against the S&P 500 (daily chart) For bullish I get 83 results and for bearish scan I get 273 results

Here is the scan code

Code:
input marketOpen = 830;
input marketClose = 1500;
input intraDaySpan = {Default "SameDay" , "OverNight"};
input numberOfDays = 1;
input numberOfYears = 0;

def okToPlot = GetLastDay() - numberOfDays <= GetDay() and GetLastYear() -...

tomsk

Well-known member
VIP
@ezrollin Per your request, I have converted the study you posted above into a scan. This is based on the underlying logic as contained in your study. I have configured this as a bullish scan. If you'd like to set this up as a bearish scan, just change the plot statement on the last line to

Code:
plot scan = bear;

I have tested both bullish as well as bearish scans against the S&P 500 (daily chart) For bullish I get 83 results and for bearish scan I get 273 results

Here is the scan code

Code:
input marketOpen = 830;
input marketClose = 1500;
input intraDaySpan = {Default "SameDay" , "OverNight"};
input numberOfDays = 1;
input numberOfYears = 0;

def okToPlot = GetLastDay() - numberOfDays <= GetDay() and GetLastYear() - numberOfYears <= GetYear() ;
def OpenCounter =  SecondsFromTime(marketOpen);
def CloseCounter = SecondsTillTime(marketClose);
def MarketHours = if OpenCounter >= 0 and CloseCounter >= 0 then 1 else 0;
def beforeMidnight = OpenCounter >= 0 and CloseCounter <= 0;
def afterMidnight = OpenCounter <= 0 and CloseCounter >= 0 ;

def Today;
def hideChartBubbles;
rec DailyHigh;
rec DailyLow;

switch (intraDaySpan) {
case "SameDay":
    Today = if GetDay() != GetDay()[1] then 1 else 0;
    DailyHigh = if MarketHours then if high > DailyHigh[1] then high else DailyHigh[1] else high;
    DailyLow = if Today then low else if MarketHours then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = MarketHours;
case "OverNight":
    Today = 0;
    DailyHigh = if beforeMidnight or afterMidnight then if high > DailyHigh[1] then high else DailyHigh[1] else  high;
    DailyLow = if beforeMidnight or afterMidnight then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = beforeMidnight or afterMidnight;
};

def TodaysHigh = if okToPlot and MarketHours then DailyHigh else Double.NaN;
def TodaysLow = if okToPlot and MarketHours then DailyLow else Double.NaN;

def bull = DailyHigh > DailyHigh[1] and MarketHours;
def bear = DailyLow < DailyLow[1] and MarketHours;

plot scan = bull;
 
Solution

Similar threads

Top