Hi there,
I am using the Daily ATR range indicator on my chart as made by Nicolas here; https://www.prorealcode.com/prorealtime-indicators/daily-atr-range-for-intraday-chart/
I am simply looking to be able to set up a screener or alert on my platform when any currency or something in my whatchlist etc breaks above or below the ATR high/Low levels that the indicator draws on my chart.
I have attached a picture of the indicator on my chart, the two orange lines are the indicator. I simply want to be able to screen or be alerted when price goes above or below either of the two lines.
Thanks very much
Dan
Does anyone have any ideas how to go about this?
Thank you
Bump for any help with this 🙂
There you go (screener not tested):
ATRperiod = 20 //change this period as you wish
dTR = 0
for i = 0 to ATRperiod
dTR=dTR+max(abs(Dhigh(i)-Dlow(i)),max(abs(Dhigh(i)-Dclose(i+1)),abs(Dlow(i)-Dclose(i+1))))
next
avg = dTR / ATRperiod
htr = Dlow(0) + avg[1]
ltr = Dhigh(0) - avg[1]
x = 0
IF close > htr THEN
x = 1
ELSIF close < ltr THEN
x = -1
ENDIF
SCREENER [x] (x AS "Signal")
Please use QUOTE only when you have to point something important out. Simply write your post in all other cases, otherwise topics will become larger and larger and difficult to read. Thank you.
Yes, we can hold the values for some bars (you will set their number), but this will also increase the list of returned value, which might be an issue when items approach or exceed the 50/100-item limit.
Anyway this is the code (not tested), should you need to restore a shorter life to items scanned just set the LOOKBACK value to 1:
LookBack = 5 //keep returned items alive for 5 bars
ATRperiod = 20 //change this period as you wish
dTR = 0
for i = 0 to ATRperiod
dTR=dTR+max(abs(Dhigh(i)-Dlow(i)),max(abs(Dhigh(i)-Dclose(i+1)),abs(Dlow(i)-Dclose(i+1))))
next
avg = dTR / ATRperiod
htr = Dlow(0) + avg[1]
ltr = Dhigh(0) - avg[1]
a = summation[LookBack](close > htr)
a = (a > 0) AND (a <= LookBack)
b = summation[LookBack](close < htr)
b = (b > 0) AND (b <= LookBack)
x = 0
IF a THEN
x = 1
ELSIF b THEN
x = -1
ENDIF
SCREENER [x] (x AS "Signal")
should ever both A and B are true, A is returned being the first value to be checked.
Sure, sorry about the quote, good point!
I got a syntax error on that amendment. It says;
“This variable is not used in the code:ltr”
I can’t spot what it relates to. I have tried changing the ATR period but it runs the same parameters as original no matter what value you put in, so maybe that is linked?
Sorry for all questions!
My fault, please replace htr in line 12 with ltr.
Also, should you not get good results with -1 in line 18, replace it with 2 (or whatever digit you prefer), just to keep it different from 1.
ah yes, works perfectly now, thank you.
Do you think there may be a reason that when you change the ATR value for days it makes no difference to the screening results – always brings the same whether = 20 or 100 say
Do you have any idea why that might be?
I duplicated it and modified one of it replacing 20 with 5 and returned items were completely different! I tried with 50 in place of 20 and got no results (on Currencies, 1-hour TF).
ah ok, strange one. I think I have a weird bug as I am changing to currency only etc and it’s still showing me other securities as well as not changing ATR period. Maybe I need a restart!
It is giving me a lot of 1/-1 signals on contracts that actually haven’t hit their ATR during the day so I don’t know why they show up, but seems to pick all others up as far as I can see so that’s not as issue, just a strange one 🙂
254 bars is surely not enough to compute correctly the daily ATR with ProScreener, depending of the timeframe used..
[attachment file=”112805″]
A good idea this alert, but doesn’t seem to work for me. See attachment, display is alerted but the atr lines were never breached
Using this code…
LookBack = 5 //keep returned items alive for 5 bars
ATRperiod = 20 //change this period as you wish
dTR = 0
for i = 0 to ATRperiod
dTR=dTR+max(abs(Dhigh(i)-Dlow(i)),max(abs(Dhigh(i)-Dclose(i+1)),abs(Dlow(i)-Dclose(i+1))))
next
avg = dTR / ATRperiod
htr = Dlow(0) + avg[1]
ltr = Dhigh(0) – avg[1]
a = summation[LookBack](close > htr)
a = (a > 0) AND (a <= LookBack)
b = summation[LookBack](close < ltr)
b = (b > 0) AND (b <= LookBack)
x = 0
IF a THEN
x = 1
ELSIF b THEN
x = -1
ENDIF
SCREENER [x] (x AS “Signal”)
>> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<
🙂