hi… Rob
I added variable J to count the very first occurrence, as it can’t be assumed it’s when I=1:
It took me a while to grasp what you comments meant. Just for other’s following at home!
When the loop starts, it doesn’t process anything until it looks back apon a high higher than the current high.
Now if that just happens to be the 1st previous bar , when i = 1, then the calculated ‘diff’ value along with it index location would be stored in the ‘If’ statements ‘xdiff’ and ‘xibar’ as the default/first found value which is used later for comparisons.
These values, but specifically, ‘xdiff’ is used to determine if following found ‘diff’ values are smaller than it. If it is, it replaces it, if its not , it lives through other iterations of the loop till it is, or the loop reaches the end and terminates.
However, when i=1 and not a higher value, then ‘no’ code in the loop is executed, that correct. But when a later, the first, higher high is found and i > 1 then this new set of values are not stored in the ‘if’ statements ‘xdiff’ and ‘xibar’ lines because the condition is false so not updating ‘xdiff’ for ‘this’ first time.
This creates a knock on affect because when it compares this first diff value, it’s comparing it to an invalid/previous, but wrong ‘xdiff’ value and also not being the first ‘xdiff’. This means that not only is it being compared to a wrong value, also any other finds are being compared to a wrong value and its not until a value registers as smaller higher high to this wrong value, that normal service is resumed, If this doesn’t correct itself before it draws, it ripples through to drawing elements, randomly not moving or making wild jumps. Just as i saw.
Thanks for your time Roberto, that’s great, learned a lot from trying to understand my own code from you comments.
Best Regards.