| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| ATR with MA https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=511 |
Page 1 of 1 |
| Author: | dynel14 [ Thu Apr 26, 2012 12:20 am ] |
| Post subject: | ATR with MA |
Hi community, hope you all are doing well...!? I have a request: Is it possible to make a histogram version of this indicator? ATR > MA = green ATR = MA = yellow ATR < MA = red I would really appreciate your help!!! Thank you in advance |
|
| Author: | dynel14 [ Sun Apr 29, 2012 8:54 pm ] |
| Post subject: | Re: ATR with MA |
Hmm.. I tried to do it, but it doesn't work. Maybe someone can fix it? THANKS! Code: Select all |
|
| Author: | garyfritz [ Sun Apr 29, 2012 11:52 pm ] |
| Post subject: | Re: ATR with MA |
You have a couple of errors. You declare ExtMapBuffer1/2 as arrays, but not pre-allocated arrays. Display buffers are automagically allocated by Empty4. For your own buffers, you have to allocate the space. You can either allocate a fixed array, e.g. "double ExtMapBuffer1[2048];", or you can resize the array to the size you want: "double ExtMapBuffer1[]; ArrayResize(ExtMapBuffer1, Bars);" or similar. Then, although you declared them as arrays, you assigned into them like a single value, without an indexer. It's also not necessary for ExtMapBuffer2 to be an array. You need the ExtMapBuffer1 array because you take the iMAOnArray of it, but the MA result gets used and discarded. So it can be a simple double. You also made a very understandable mistake -- because Empty4's definition is braindead. In bar data, the [0] bar is the newest, rightmost bar. So if you do an iMA on it, it includes bar i and the bars with indexes GREATER THAN i. (A 3-bar SMA would include bar i, i+1, i+2 -- i+1 is "older" than i.) But normal arrays are indexed "left-to-right," with [0] being the "oldest." So an iMAOnArray SMA includes bar i, i-1, and i-2. You need to SetArrayAsSeries to make Empty4 treat the array like bar data, reversing the order that iMAOnArray access it, AND you need to scan i from oldest to newest (iNewBars to 0) so the older ATR data is in the ExtMapBuffer1 array for iMAOnArray to access. Finally, your "return(0)" was INSIDE your i loop! Whoops! So I think the attached does what you wanted. You won't see many (any?) yellow bars, because the two values will almost never be exactly equal. If you really want yellow bars for "equal" values, you'll have to do something like "if (MathAbs(x-y) < 0.00001) then ..." instead of using ==. I don't guarantee this code is done the "right way." I just figured out some of these mysteries myself last week, thanks to sq! Gary Code: Select all |
|
| Author: | dynel14 [ Mon Apr 30, 2012 12:12 am ] |
| Post subject: | Re: ATR with MA |
Thank you very much :!: Will try to understand all my mistakes. I have no clue about coding. I have just started to learn it. Thanks again :!: |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|