Simple screener not working, can't find mistake

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #54313 quote
    jbyrne
    Participant
    Average

    Hi, I’m trying to make a simple screener that alerts me when a stock’s highest/lowest price in the first 1 hour of the day is at least 0.5% from the prev-day close and also down/up at 1% on prev-day close. In case that explanation wasn’t very good, here’s a picture explaining it; https://gyazo.com/7a62b441759ee8c7a9a572de9f0a6923

    Here’s my code(V1 and V2)

    I suspect it might be a syntax mistake since my screener is listing way more stocks than it should be, from my experience, which is what tends to happen whenever a syntax is wrong.

    Can anyone correct my mistake(s) and help me out? Posting here is my last resort, after search everywhere I could.

    Thanks in advance.

    timeframe (1hour)
    
    Hour1Start = 080000
    Hour1End = 090000
    
    if time > Hour1Start and time < Hour1End then
    H1low = dlow(0)
    endif
    
    if time > Hour1Start and time < Hour1End then
    H1High = dhigh(0)
    endif
    
    timeframe (daily)
    
    BullOnDay = variation>1
    BearOnDay = variation<-1
    
    GapUp = (H1High-Close[1])/H1High
    
    GapDown = (Close[1]-H1Low)/Close[1]
    
    HighCheck = H1High > Close[1]
    LowCheck = H1Low < Close[1]
    
    GapCheckUp = GapUp >= 0.005
    GapCheckDown =  GapDown >= 0.005
    
    CheckUp = GapCheckUp and HighCheck
    CheckDown = GapCheckDown and LowCheck
    
    UpGap = GapUp and CheckUp
    DownGap = GapDown and CheckDown
    
    Bull = DownGap and BullOnDay
    Bear = UpGap and BearOnDay
    
    
    SCREENER [Bull or Bear] (Bull as "Bull")
    timeframe (1hour)
    
    Hour1Start = 080000
    Hour1End = 090000
    
    if time > Hour1Start and time < Hour1End then
    H1low = dlow(0)
    endif
    
    if time > Hour1Start and time < Hour1End then
    H1High = dhigh(0)
    endif
    
    timeframe (daily)
    
    BullOnDay = variation>1
    BearOnDay = variation<-1
    
    if H1low < Close[1] then
    
    GapDown = (Close[1]-H1Low)/Close[1]
    
    GapCheckDown = GapDown >= 0.005
    
    DownGap = GapDown and GapCheckDown
    endif
    
    if H1High > Close[1] then
    
    GapUp = (H1High-Close[1])/H1High
    
    GapCheckUp = GapUp >= 0.005
    
    UpGap = GapUp and GapCheckUp
    endif
    
    Bull = DownGap and BullOnDay
    Bear = UpGap and BearOnDay
    
    
    SCREENER [Bull or Bear] (Bull as "Bull")

     

     

    #54340 quote
    robertogozzi
    Moderator
    Master

    To make a link clicky, please use the “insert/edit link” button identified by a chain connector on the grey bar when you write your post so it becomes https://gyazo.com/7a62b441759ee8c7a9a572de9f0a6923.

    You should replace lines 6-12 (both versions) with:

    if time >= Hour1Start and time <= Hour1End then
       H1low  = low
       H1High = high
    endif

    because time > Hour1Start is 9 AND time < Hour1End is 8 and they exclude each other. Adding “=” should make it work!

    Also, since you are in a HOURLY timeframe, the highest & lowest prices between 080000 and 090000 are returned by the keywords HIGH and LOW of the candle closing at 090000 (which started at 080000), so you should replace lines 3-4 with:

    Hour1Start = 090000
    Hour1End   = 090000

    They are just the more visible mistakes I can easily spot. I will try to code it my own way and then post it later today.

    Roberto

    jbyrne thanked this post
    #54341 quote
    robertogozzi
    Moderator
    Master
    Hi, I’m trying to make a simple screener that alerts me when a stock’s highest/lowest price in the first 1 hour of the day is at least 0.5% from the prev-day close and also down/up at 1% on prev-day close.

    So 0.5% is +0.5% (not -0.5%)?

     

     

    jbyrne thanked this post
    #54356 quote
    jbyrne
    Participant
    Average
    Hi, I’m trying to make a simple screener that alerts me when a stock’s highest/lowest price in the first 1 hour of the day is at least 0.5% from the prev-day close and also down/up at 1% on prev-day close.
    So 0.5% is +0.5% (not -0.5%)?


    Thanks for above corrections, I have added them to my code but it still doesn’t work. I am no longer getting too many stocks in my screener, I now have none.

    0.5% is just a minimum benchmark from the close to the high or low. The difference between the close and high/low has got to be at least 0.5%.

    It can be either +0.5% or -0.5% depending on if it’s a bull or bear signal. In the picture/screenshot I previously sent, the signal is bullish so the 0.5% is -0.5%. If that chart was flipped to become bearish, it would be +0.5%. Hope thats makes things more clear. 

    #54816 quote
    robertogozzi
    Moderator
    Master
    Hi, I’m trying to make a simple screener that alerts me when a stock’s highest/lowest price in the first 1 hour of the day is at least 0.5% from the prev-day close and also down/up at 1% on prev-day close.

    Since you used AND, there’s no need to check +-0.5%, checking 1% will do both.

    I tried to write this code, please test it and give me some feedback. I did not test it much:

    ONCE DayLow    = 0
    ONCE DayHigh   = 0
    ONCE Hlow      = 0
    ONCE Hhigh     = 0
    ONCE HourStart = 090000
    
    MyAlert = 0
    
    timeframe (daily)
       DayHigh = Dhigh(0)
       DayLOw  = Dlow(0)
       
    timeframe (1 hour)
       if time = HourStart then
          Hlow  = low
          Hhigh = high
    	  MyAlert = (Hlow >= (DayHigh * 1.01)) OR (Hhigh <= (DayLow * 0.09))
       endif
    
    timeframe (default)
    
    SCREENER [MyAlert] (MyAlert as "Bull/Bear")
    jbyrne thanked this post
    #54832 quote
    jbyrne
    Participant
    Average

    Hi, thanks for getting back to me.

    I just pasted your code into a new screener, and I get no new results; it still doesn’t work.

    I’m not sure what you mean by the following “Since you used AND, there’s no need to check +-0.5%, checking 1% will do both.” since the first hourly low/high being 0.5% from close is a key requirement, and I only want to be alerted once the stock has reached 1% from close. Maybe I misunderstood what you said, but it seems like theres some confusion I hope this clears any.

    Thanks in advance

     

     

    #54887 quote
    robertogozzi
    Moderator
    Master
    Hi, thanks for getting back to me. I just pasted your code into a new screener, and I get no new results; it still doesn’t work. I’m not sure what you mean by the following “Since you used AND, there’s no need to check +-0.5%, checking 1% will do both.” since the first hourly low/high being 0.5% from close is a key requirement, and I only want to be alerted once the stock has reached 1% from close. Maybe I misunderstood what you said, but it seems like theres some confusion I hope this clears any. Thanks in advance


    Since you wrote “I only want to be alerted once the stock has reached 1% from close” you only need to check 1%, since it includes 0.5%.

    jbyrne thanked this post
    #54900 quote
    jbyrne
    Participant
    Average

    I’m confused as to why you wouldn’t need to check if the distance between the close and highest/lowest is 0.5%, since the 0.5% distance isn’t counted from close, since it is either below or above the close.

     

    I’ve attached a picture showing what I want my screener to achieve. The distance between the red circles has to be atleast -0.5% and I need the screener to tell me when the difference between the blue circles is +1%. 

     

    Thanks

    temp-stock.png temp-stock.png
    #54902 quote
    robertogozzi
    Moderator
    Master

    Please attach a detailed example, you might use a spreadsheet to make it, with each candle tagged with the time it is formed.

    I can’t understand why you drew a red circle below the red candle and the other one below the green candle by its side.

    jbyrne thanked this post
    #54903 quote
    jbyrne
    Participant
    Average

    I drew a red circle around the previous day close, and around the lowest point of the opening hour the next day. I included the time/day bar at the bottom of the screen in hopes of showing this.

     

    Bull example:

     

    Stock price at previous day close = 10

    Stock price at low of first hour candle = 9.9

    Difference between close and lowest point in first hour = -1%

    -1% is bigger than the minimum requirement of -0.5%, which is what we are looking for.

    Stock price then increases to 10.1

    Difference between previous day close(10) and current price(10.1) is +1%, at this point, the screener alerts.

     

    Bear example:

    Stock price at previous day close = 10

    Stock price at high of first hour candle = 10.1

    Difference between close and lowest point in first hour = +1%

    +1% is bigger than the minimum requirement of +0.5%, which is what we are looking for.

    Stock price then decreases to 9.9

    Difference between previous day close(10) and current price(9.9) is -1%, at this point, the screener alerts.

     

    No alert bull example:

    Stock price at previous day close = 10

    Stock price at low of first hour candle = 9.98

    Difference between close and lowest point in first hour = -0.2%

    -0.2% is below the minimum requirement of -0.5%, which means we dont care about it.

     

    I hope this helps

    #54904 quote
    robertogozzi
    Moderator
    Master

    Now I got it!

    I’ll try to arrange something tomorrow morning.

    jbyrne thanked this post
    #54905 quote
    jbyrne
    Participant
    Average

    Great! I’m glad that got cleared up.

     

    Just seen a small typo in my comment;

    Under “Bear example”, the line “Difference between close and lowest point in first hour = +1%”, should be; “Difference between close and HIGHEST point in first hour = +1%”

    #55044 quote
    robertogozzi
    Moderator
    Master

    Try this one (I did not test it, though):

    ONCE MaxPercent = 0.01
    IF IntradayBarIndex = 0 THEN                           //Check the first hourly bar each day
       YesterdayClose = close[1]                           //Data from yesterday's last bar
       //   Bullish
       FirstHourHigh  = YesterdayClose * (1 + MaxPercent)
       //   Bearish
       FirstHourLow   = YesterdayClose * (1 - MaxPercent)
    ELSE
       BullAlert = close >= FirsrHourHigh
       BearAlert = close <= FirsrHourLow
       MyAlert   = BullAlert OR BearAlert   
    ENDIF
    SCREENER [BullAlert OR BearAlert] (MyAlert as "Bull/Bear")
    

    This will work on a hourly TF, to make it work on, say, 5min TF a bit more work is needed. If it works on an hourly TF we can further adapt it to other TFs.

    Still, I have no idea what to do with 0.5%; it is useless, since you only want to be alerted when the price reaches +-1% (which is bigger than+-0.5%).

     

    Nicolas and jbyrne thanked this post
    #55733 quote
    jbyrne
    Participant
    Average

    Hi, thanks for the help. I apologize for not responding instantly, as I have been away from internet access for the last week.

    I have tried your new code, it still doesn’t work. It returns lots of stocks that don’t have anything to do with what I’m looking for.

     

    Still, I have no idea what to do with 0.5%; it is useless, since you only want to be alerted when the price reaches +-1% (which is bigger than+-0.5%).

    As I explained before, the 0.5% is not measuring anything but the difference in price from the previous days close, and the high(Bear) or low(Bull) of the first candle. If the difference is bigger than -0.5% then I want to be alerted once the stock reaches +1%(Bull signal) and if the difference is bigger than +0.5%, then I need to be alerted when the stock reaches -1%(Bear signal). So, the 0.5% is definitely needed, since it’s the opposite direction of the 1%.

    Here’s a visual of what I would like to achieve. This chart attached is a bull signal.

    Chart Key;

    1 = Previous day close (30/10/17)

    2 = Low of first hour (31/10/17)

    3 = Stock reaches +1% difference from Previous day close(1)

     

    As you can see; the difference between the Previous day close, labelled “1”(px : 1203.5) and the low of the first hour, labelled “2”(px: 1261) is -2.51%. -2.51% is above the minimum requirement of -0.5% for a Bull signal, so this is what we are looking for. For the screener to alert, we need the difference between the previous day close(“1”) and the current price to be +1%. The stock pictured, reaches +1% at point “3” on the chart.

    The general idea of this pattern is the stock price going from negative to positive(Bull) or positive to negative(Bear) within the first hour of the day. 

    Hope this helps

    temp-stock-1.png temp-stock-1.png
    #55751 quote
    robertogozzi
    Moderator
    Master

    What I did not understand was  that 0.05% had to be -0.05% for BULLish setups and +0.05% for BEARish setups. Now it’s clear.

    I hope it works as you asked (any feedback is always and highly welcomed):

    ONCE MaxPercent             = 0.01
    ONCE PreviousHighLowPercent = 0.005
    IF IntradayBarIndex = 0 THEN                                                      //Check the first hourly bar each day
       YesterdayClose       = close[1]                                                //Data from yesterday's last bar
       //   Bullish
       FirstHourHigh        = YesterdayClose * (1 + MaxPercent)
       FirstHourMinimumLow  = low <= (YesterdayClose * (1 - PreviousHighLowPercent))  //true if low  <= -0.5% of the previuos day
       //   Bearish
       FirstHourLow         = YesterdayClose * (1 - MaxPercent)
       FirstHourMinimumHigh = high >= (YesterdayClose * (1 + PreviousHighLowPercent)) //true if high >= 0.05% of the previous day
    ELSE
       BullAlert = (close >= FirstHourHigh) AND FirstHourMinimumLow
       BearAlert = (close <= FirstHourLow)  AND FirstHourMinimumHigh
       MyAlert   = BullAlert OR BearAlert
    ENDIF
    SCREENER [BullAlert OR BearAlert] (MyAlert as "Bull/Bear")

     

    jbyrne thanked this post
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

Simple screener not working, can't find mistake


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
jbyrne @jbyrne Participant
Summary

This topic contains 14 replies,
has 2 voices, and was last updated by robertogozzi
8 years, 3 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 11/29/2017
Status: Active
Attachments: 2 files
Logo Logo
Loading...