Hello!
I’m trying to code an Average Daily Rate indicator which includes a trading week of daily prices. I’d like to show it independently below the chart in a separate area.
This is my code
// Default Period = 7
//ADR Average Daily Rate
ADR = Average(Average[DHigh(0)-Dlow(0)]+Average[DHigh(1)-Dlow(1)+Average[DHigh(2)-Dlow(2)+Average[DHigh(3)-Dlow(3)+Average[DHigh(4)-Dlow(4)+Average[DHigh(5)-Dlow(5)+Average[DHigh(6)-Dlow(6)]]]]]])
r=255
g=0
b=0
return ADR coloured(r,g,b) style(Line, 5) as "ADR"
When I try to add this indicator to my chart, I get the following error:
“A positive integer field is expected with Average”
What am I missing here?
Many thanks in advance for your help!
Are you sure you are not confounding with an Average Daily Range? Which is the X days average or each bar range. Recent french topic (and code) about ADR: https://www.prorealcode.com/topic/probleme-sur-indicateur-range-daily/
Hello Nicolas,
Thank you very much for your reply. Yes, I actually meant the “Average Daily Range”. I’ve read the post you pointed out, but I’m still not sure if using the following code (with daily prices) would give me the ADR indicator that I’m looking for, and if this is equivalent to the formula I was using before. I would appreciate if you could confirm.
a= Average[7](Dhigh(1)-Dlow(1))
Return a coloured(255,102,0) as "Average Daily Range"
Thanks!
Your formula was wrong because you were using daily price values as period?
This last code is not good if you want to use it on a timeframe inferior to the daily one. It also includes 7 days prior to the current one, which is not included, I don’t know if you want to include the current day or not?
Hi Nicolas,
I don’t know what was wrong with it, but I’m getting the error “A positive integer field is expected with Average” when I try to use it.
I just need an indicator that returns the Average Daily Range for each trading day up to the previous one. So I’m not interested in the current one. My timeframe is 1 day.
I’m only using daily candles, and I would like to view it below my chart, like some other pre-built indicators I’m currently using.
Many thanks in advance for your reply.
If you just want an average of the last seven days ranges then the last code you posted works just fine.
If you want the average for Mondays and the Average for Tuesdays and the average for Wednesdays then that is something totally different.
How can I display the ADR of a stock for one month on screen as I don’t need this as separate indicator.
Could you please share the code for that? Thanks.
To display whatever om screen you need an indicator.
If you want to display it one month only, simply remove it when no more needed.
I am not sure I understood what you mean, though.
I need to know which one is correct ADR formula for last one month ADR. I have following two codes and there is some variation comes in between these two results:
c1 = Volume >8900000
ADR= Average[20](Dhigh(1)-Dlow(1))
SCREENER[c1] (ADR AS "ADR Rating")
c1 = Volume >8900000
ADR = average[20,0](range)
SCREENER[c1] (ADR AS "ADR Rating")
Moderators Edit: Post edited – please use the ‘Insert PRT Button’ when inserting code in your posts.
If used ina Daily TF they are identical, but for the fact that the first one (Dhigh(1)-Dlow(1)) refers not to the last 20 periods, but to the previous 20 periods (not including today). You could use RANGE[1] to the second screener to make them match.
If they are not used in a Daily TF, the first one correctly uses DAILY values (apart from the starting offset as explained above), while the second one refers to the RANGE according to the involved TF.
In the first part of my last post I wrote “for the fact that the first one (Dhigh(1)-Dlow(1)) refers not to the last 20 periods, but to the previous 20 periods”.
The correct version is “due to the fact that the first one (Dhigh(1)-Dlow(1)) refers not to the last 20 periods, but to the previous 20 days”.
Sorry for any misunderstanding this may have caused.
Sorry, I didn’t understand. What’s the difference between 20 periods and 20 days? On Daily chart they both will be same? what about in hourly chart?
The difference is on charts other than the daily one.