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:
- Above their ATR stop line
- 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"
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")
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.
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!
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")
Thank you very much Roberto! I shall experiment with the new codes 🙂
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.
Excellent. Will do. Thank you !