Hi. I have a script that calculates and returns an ADR result(ADR in dollars, across the last 20 daily candles).
Also, I’m sure there is an easier way to calculate this, but this is what I’m currently working with:
DR=High-Low
ADR=(DR[0]+DR[1]+DR[2]+DR[3]+DR[4]+DR[5]+DR[6]+DR[7]+DR[8]+DR[9]+DR[10]+DR[11]+DR[12]+DR[13]+DR[14]+DR[15]+DR[16]+DR[17]+DR[18]+DR[19])/20
Return ADR
My questions are:
- Is it possibly to get this result to show on the price chart in a label or bubble or similar, to appear near top of chart or near description or other, instead of regular chart type?
- Can I use TimeFrame to somehow show the Daily ADR as a DAILY average only, not changing with selected chart timeframe?
Thanks
Hi, here is another way to calculate ADR.
defparam drawonlastbaronly=true
dr=high-low
adr=summation[20](dr)/20
if islastbarupdate then
drawtext("ADR=#adr#",-100,-100)anchor(topright,xshift,yshift)
endif
Return
Here are some examples with the timeframe: https://www.prorealcode.com/documentation/timeframe-probacktest-proorder/
Awesome! Thanks so much! Works perfectly!
Hi. I made some adjustments to placement, font and color, but I still can’t figure out how to use Timeframe or other to always return the daily ADR regardless of chart timeframe I’m viewing.
JSParticipant
Senior
If you want to use multiple timeframes, you can place the calculation of the indicator under the desired timeframe (in this case, daily) and the output (text, plot, print) under the “Default” timeframe…
DefParam DrawOnLastBarOnly=True
TimeFrame(Daily, UpdateOnClose)
Period=20
DR=High-Low //or DR=Range
ADR=Average[Period](DR)
TimeFrame(Default)
drawtext("ADR=#adr#",-100,-100)anchor(topright,xshift,yshift)
Return
Sorry it took me so long getting around to trying this, but I tried a couple of different ways with no success. I have slightly different position setting, but didn’t think that should make a difference.
JSParticipant
Senior
If I have understood everything correctly, you want to display the daily ADR label in the chart while the chart’s timeframe can change…
At least, this is what the code is written for and what it also executes…
When I load the indicator into the chart (on the price), the ADR label appears in the top right corner of the chart. Now, if I change the chart’s timeframe, for example, to 1 hour (15k units), the label remains in the same position, and the value also stays the same…
Thank you. Not sure what other setting is different on my end, but I get errors when changing timeframes. I even tried changing units as well in case that made a difference. Copied and pasted also to be sure i didn’t mistype.
And, it’s really great as is, it’s not like I live off that item. Just a minor house cleaning type thing if I could get it resolved.
JSParticipant
Senior
According to the error message, you are currently using:
ADR = Average[20](High – Low)
Which is not necessarily wrong…
A better approach might be:
DR = (High – Low)
ADR = Average[20](DR)