| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Want to make an ADR without using Period_D1 https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3729 |
Page 1 of 1 |
| Author: | Stearno [ Mon Jul 14, 2014 5:17 pm ] |
| Post subject: | Want to make an ADR without using Period_D1 |
I am relatively new to programming and trying to learn by deciding what I want to do and then researching and investigating how to do that one thing. I learn a lot and find it easier to learn with real world application. I want the ADR(20) in the buffer for each candle, for a defined session. In my thinking right now session and day are interchangeable, because my intention in the way I think I am writing this indicator is so I could easily modify it to be for market sessions, not only days, in the future. Also, I don't want to use Period_D1, because then it will not work in backtesting, which is the main reason I need it at this time (otherwise I just use an existing ADR indicator, or use iATR with Period_D1). But I can easily see the need (or maybe it is just nice to have) this indicator to see the average range for a particular session (e.g. first 2 hours of the London open) and compare that to other periods of time. I have looked at many examples of ADR indicator code on internet, but almost every one of them uses Period_D1 (which by using that makes the job easy, but does not meet my requirements). Where I have gotten is I have calculated the previous day's range (a session length and the session end hour are defined in the indicator). The difficulty I am having is getting the 20 session periods' ranges summed and then averaging them by 20. I have used a loop, but it just does not compare to when I use Period_D1 as a sanity check. So I figured there is a bug in my code. How can I fix what I have? Any suggestions? Here is a piece of my code: Code: Select all This piece of code is used when the current candle is after the end of the last session hour. At the first 'if' statement, i find out where the current candle is compared to the session close hour. If the current candle time is after the session's close, then it goes here. First I calculate the number bars away the beginning of the session is from the current candle. This then gives me the shift I need to get to the sessions' close. Then I can calculate how many bars are in the session by dividing the number of hours of the session length by the chart period. Then I use the shift and the session length for the ihighest and ilowest, within a loop. The loop continues 20 times. I then take that and sum at the end of the loop and divide by 20. Then I place that in the buffer and it goes on to the next candle in the original loop. So as I said, the ADR does not appear to be correct. I appreciate any guidance, explanations, example code, etc. I am first to admit that my method of code might not be the best, cleanest, nor the quickest way. But it is how my thought process was and the extent of my understanding so far to this point. If I may be so bold to presume to ask, but could you focus your guidance and advice to help me fix my current way of doing it. If it is completely wrong and there is no way for me to accomplish my goal, then sure, I am ready to hear that and learn the proper way. But if I can do it with making some changes with what I have, I would like that more. I thank you in advance. -Stearno |
|
| Author: | Stearno [ Wed Jul 30, 2014 2:48 pm ] |
| Post subject: | Want to make an ADR without using Period_D1 |
I figured out a different way of doing the code. I think this is cleaner. But the problem is now it only gives me the range for the previous session. It does not do the average. What is the next step I should take to fix this? Thank you for your help. -Stearno |
|
| Author: | ruktoa [ Mon Aug 04, 2014 6:59 pm ] |
| Post subject: | Want to make an ADR without using Period_D1 |
ASR Calculation - draft 7 - fix averaging problem_wa.mq4 - formatted by AStyle. (AStyle --style=kr -oOt3) - some workaround ASR_Simple.mq4 - used ATR.mq4 as template. - draw last bar of the session only AverageSessionRangeRww.mq4 - draw all bars |
|
| Author: | Stearno [ Tue Sep 09, 2014 6:03 am ] |
| Post subject: | Want to make an ADR without using Period_D1 |
Sorry, I have taken so long to respond. I recently had a baby and have taken a break from trading for the first while with my new boy. He takes a little bit of my time and attention. He mostly looks like this: Back to the indicators. I appreciate your reply. Thank you for your help. For ASR_Simple.mq4 and AverageSessionRangeRww.mq4, they do not show anything in the indicator window, nor in the buffers. I don't know if I need to do anything more to the code to get them to work. As for your feedback on the draft 7 indicator, when I load the -wa version on the chart, it does show a number in the buffer, but it basically counts down as you move from left to the right. It is not averaging. I think I figured out the solution as I was studying your changes. As seen in the attached pic, I put "SumSession = 0". Now it appears to be averaging and not just adding everything up. Funny how it is a simple error that is usually the problem. In your code, I did notice the changes you made. I wanted to see if I could ask the 'why' behind the changes, so I can better learn: * I think the comment is yours where it says "(1440/ChartPeriod1)" might not previous day" Why will it not be the previous day? Is there a better way to find the previous day? * Why do I need "static" before the date on the "atime"? * for the first "itimeinseconds" variable, it was "iTimeInSeconds = Time[j + (1440/ChartPeriod1)];" Why does I need to multiply"(i-1)" to the result of "1440/ChartPeriod?" * on the High and Low, why do I need to add 1 to the (begin - end) bar shifts? Now that I have it averaging properly, I will start to double check the math to ensure it is giving the correct average. So your above comments will become important to the accuracy I am sure. Again, thank you for your help. -Stearno |
|
| Author: | Stearno [ Tue Sep 09, 2014 9:11 am ] |
| Post subject: | Want to make an ADR without using Period_D1 |
---Update---- I was wrong. It is not averaging, it is just showing the range in pips of the previous session. In version 9, I even tried just doing an array and manually adding the sessions together and dividing by 20. But it results in a very similar number to version 8, but off by a few pips. I manually measured the sessions on the chart and calculated the average in excel. The average did not match the indicator. Any suggestions? -Stearno |
|
| Author: | Stearno [ Tue Sep 09, 2014 1:24 pm ] |
| Post subject: | Want to make an ADR without using Period_D1 |
Okay, new attempt. I am still using the arrrays to add the values. But in this version, I am using the buffers to show the array values. So the array values are the same. What is wrong with my "for" cycle or with my assigning the value to the array element? -Stearno |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|