List of Stocks below ATR Stop Line

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #76550 quote
    rowestock
    Participant
    New

    List of Stocks/Instruments above/below ATR Stop Line

    The code below is the ATR stop line indicator (very similar to “Supertrend”).

    I would like to create a screener which finds stocks which are trading:

    1. Above their ATR stop line
    2. Below their ATR stop line

    Can someone help?

    Many thanks 🙂

    // Période
    p = 10
    
    // Average True Range X
    ATRx = AverageTrueRange[p](close) * 3.0
    
    // ATRts = ATR Trailing Stop
    // Inversion de tendance
    IF close crosses over ATRts THEN
    ATRts = close - ATRx
    r=0
    g=200
    ELSIF close crosses under ATRts THEN
    ATRts = close + ATRx
    r=200
    g=0
    ENDIF
    
    // Cacul de l'ATRts lors de la même tendance
    IF close > ATRts THEN
    ATRnew = close - ATRx
    IF ATRnew > ATRts THEN
    ATRts = ATRnew
    ENDIF
    ELSIF close < ATRts THEN
    ATRnew = close + ATRx
    IF ATRnew < ATRts THEN
    ATRts = ATRnew
    ENDIF
    ENDIF
    
    
    return ATRts coloured(r,g,0) as "ATR Trailing Stop"
    
    #76560 quote
    robertogozzi
    Moderator
    Master

    This is the code, but it will return tons of lines, you’ll have to filter them!

    // Période
    p = 10
     
    // Average True Range X
    ATRx = AverageTrueRange[p](close) * 3.0
     
    // ATRts = ATR Trailing Stop
    // Inversion de tendance
    IF close crosses over ATRts THEN
    ATRts = close - ATRx
    //r=0
    //g=200
    ELSIF close crosses under ATRts THEN
       ATRts = close + ATRx
       //r=200
       //g=0
    ENDIF
     
    // Cacul de l'ATRts lors de la même tendance
    IF close > ATRts THEN
       ATRnew = close - ATRx
       IF ATRnew > ATRts THEN
          ATRts = ATRnew
       ENDIF
    ELSIF close < ATRts THEN
       ATRnew = close + ATRx
       IF ATRnew < ATRts THEN
          ATRts = ATRnew
       ENDIF
    ENDIF
    
    x = 0
    IF close > ATRts THEN
       x = 1
    ELSE
       x = 2
    ENDIF
    SCREENER [x] (x AS "1=above/2=below")
    #76561 quote
    rowestock
    Participant
    New

    Excellent thanks Roberto. Is there a way to make the list more than 50 results?  See screenshot.

    Also, is there a way to see the 1 & 2 (Above & Below) results in one window?  I can only separate the results of the screener using the “creation by programming” tab.

    Capture.jpg Capture.jpg
    #76582 quote
    robertogozzi
    Moderator
    Master

    That limit cannot be changed, as of this version of PRT.

    You could duplicate the screener and have one of them return only 1’s and the other only 2’s. This way you’ll double the list, but will also double the screeners you’ll have to open.

    If you don’t have problems with the number of screeners open, you can select commodities on one of them, currencies on a duplicate, and so on!

    There’s no workaround.

    You could, for example, only stocks NOT above/below, but those where a crossing over/under is occurring, replacing lines 33-37 with:

    IF close CROSSES OVER ATRts THEN
       x = 1
    ELSIF close CROSSES UNDER ATRts THEN
       x = 2
    ENDIF

    or scan those stocks that are not just above/below now, but have been above/below for at least the last 3 bars, or setting an increasing number to sort them, one screener showing the first 50 lines, another one another 50 lines… I’ll work on that!

    filters are the only chance to get less than 50 lines!

    #76595 quote
    robertogozzi
    Moderator
    Master

    This is the version with CROSSOVERs

    // Période
    p = 10
     
    // Average True Range X
    ATRx = AverageTrueRange[p](close) * 3.0
     
    // ATRts = ATR Trailing Stop
    // Inversion de tendance
    IF close crosses over ATRts THEN
    ATRts = close - ATRx
    //r=0
    //g=200
    ELSIF close crosses under ATRts THEN
    ATRts = close + ATRx
    //r=200
    //g=0
    ENDIF
     
    // Cacul de l'ATRts lors de la même tendance
    IF close > ATRts THEN
    ATRnew = close - ATRx
    IF ATRnew > ATRts THEN
    ATRts = ATRnew
    ENDIF
    ELSIF close < ATRts THEN
    ATRnew = close + ATRx
    IF ATRnew < ATRts THEN
    ATRts = ATRnew
    ENDIF
    ENDIF
    
    x = 0
    IF close CROSSES OVER ATRts THEN
    x = 1
    ELSIF close CROSSES UNDER ATRts THEN
    x = 2
    ENDIF
    
    SCREENER [x] (x AS "1=above/2=below")
    #76596 quote
    rowestock
    Participant
    New

    Thank you very much Roberto! I shall experiment with the new codes 🙂

    #76597 quote
    robertogozzi
    Moderator
    Master

    This is the version scanning for Stocks/Pairs being Above/Below for the latest 40 bars:

    // Période
    p = 10
     
    // Average True Range X
    ATRx = AverageTrueRange[p](close) * 3.0
     
    // ATRts = ATR Trailing Stop
    // Inversion de tendance
    IF close crosses over ATRts THEN
    ATRts = close - ATRx
    //r=0
    //g=200
    ELSIF close crosses under ATRts THEN
    ATRts = close + ATRx
    //r=200
    //g=0
    ENDIF
     
    // Cacul de l'ATRts lors de la même tendance
    IF close > ATRts THEN
    ATRnew = close - ATRx
    IF ATRnew > ATRts THEN
    ATRts = ATRnew
    ENDIF
    ELSIF close < ATRts THEN
    ATRnew = close + ATRx
    IF ATRnew < ATRts THEN
    ATRts = ATRnew
    ENDIF
    ENDIF
    
    LookBack = 40
    x = 0
    IF summation[LookBack](close > ATRts) = LookBack THEN
    x = 1
    ELSIF summation[LookBack](close < ATRts) = LookBack THEN
    x = 2
    ENDIF
    
    SCREENER [x] (x AS "1=above/2=below")

    I could not find a way to set a count to limit display to the first 50 lines, or the second 50 lines, and so on…

    I’ll try to find a way, but remind me within, say, 10 days.

    #76598 quote
    rowestock
    Participant
    New

    Excellent. Will do. Thank you !

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

List of Stocks below ATR Stop Line


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
rowestock @rowestock Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by rowestock
7 years, 7 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 07/23/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...