for (int i = AllObjects; i >0 ; i--)
Should be
for (int i = AllObjects-1; i >=0 ; i--)
Ah.. yes. that fixed it. Thank you.
But... now my question is, why does it behave that way? Because that's the first object and as far as I know it first counts all the objects which (even with only one line) should be > 0 and then starts counting down until it reaches zero.
Also, because it should count the objects from right to left on the chart, I assume that it would find at least the very first (oldest) one and maybe miss out on the newest line because the counter has reached 0 on bar 0.
Because the objects are indexed 0 ... n-1, and not 1 ... n. Please see the example code in the documentation — ObjectsTotal - Object Functions - MQL4 Reference
Also, the object index has nothing to do with bar indexing or shift. They are totally unrelated.
The object indexing does not signify left to right or right to left. The objects can be in any order because their positions are defined by either their anchor points or graphical coordinates, and not their object indexing.
- docs.mql4.com
Because the objects are indexed 0 ... n-1, and not 1 ... n. Please see the example code in the documentation — ObjectsTotal - Object Functions - MQL4 Reference
Also, the object index has nothing to do with bar indexing or shift. They are totally unrelated.
The object indexing does not signify left to right or right to left. The objects can be in any order because their positions are defined by either their anchor points or graphical coordinates, and not their object indexing.
Makes sense. :)
I kind of figured that because of the for loop running through the bars (in order) the results would also be in order instead of accessed directly.
Guess I can always try and add the line details to an array and then sort the array.
Thank you for your input.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I've got this weird issue that I haven't been able to find the answer to, so now I turn to you and hopefully you know what's happening.
As a relatively new "student", I'm still experimenting with code and see how it all works together.
I've been experimenting with finding objects, and then getting their details so I can use them.
I've written a fairly simple EA which creates a vline on the open of each new bar. Then it loops through all object on charts from the OLDEST candle to the most recent, finding all objects (in this case vertical lines, OBJ_VLINE) and then print the names and prices starting with the oldest first. etc etc...
But, it refuses to find the very first (again, the oldest) line. Even with successive loops. Object count seems to always be one higher than the line count. (not just by the code, but also confirming visually).
3 lines on the chart, 3 objects in the comment section, 2 lines printed.
It does not matter whether I run this code on a live chart or in the tester and neither does the period.
I would understand if it wouldn't find the line at Bar 0 because maybe it would count the lines and it had not been created yet, but as far as I know this code should be counting from right to left on the chart. So i see no reason why it would skip the first one.
I'm at a bit of a loss here. lol. thanks for any insights :)