Help with Division

May be a simple question for the experts. I am not able to get the correct result for the below division formula. Can you let me know what is the correct way to put it?


Seriously, what does "not able to get correct result" mean?
Do you think there are magicians here being able to read your mind?
Provide detail! What is correct result and what isn't?
Apparently you have forgotten to add brackets. Yes? No?
And one thing is for sure... your formula can be simplified to just one Ref() call.

period = 3;
array = (C-L) / (H-L+1e-9);
prev_array = Ref( array, -period);

@George-The-Trader, to undersatand why you need to add round brackets (aka parentheses), please, review the "Operator precedence and the parentheses" section here (scroll down, near the middle of the document).


Order of operation is not AmiBroker specific thing but it is elementary school math. It's astonishing (to me based on real life experience) that there are so many people out there who do not even understand those simple rules. Have they been sleeping back then or been distracted because of the teacher being too attractive or...?

But that being said there is not anything said in 1st post about what is supposed to be correct (expected) result and what is not. So perhaps he is aware of order of math operations but is expecting something different (Next weeks lottery numbers? Or the attractive teacher of back then being drawn on chart? Or...?).

@George-The-Trader, the division is occurring before the subtraction which I am guessing is not your preference. Follow the posts above to divine your solution.

Try not to hit yourself on the head too hard after you figure it out.

1 Like

Thank you guys. Yes i had tired with the parenthesis as well but was getting a 505 error. it seems that by adding "+1e-9" the error is fixed. @fxshrat could you explain why "+1e-9" needs to be added to the formula?

If you want to learn quick, you need to search and read through all the stuff. After that, think about it.
its very easy to get easy answers in life but it wont take you far.

why +1e-9? bcos you were not taking care of H-L = 0. What happens when you divide by 0 ? the rest is for you to figure out.


sure i get it. thank you @travick

1e-9 is just a very low number close to zero. 1e-9 is scientific notation and means 1 x 10^(-9) and is a number with 9 decimal places -> 8 times 'zero' and one time 'one' right of comma. It could also be added 1e-20 etc... So such a very low number added to possible zeroes of H-L results in division by a very low number close to zero but not division by zero. So no warning anymore then.

"Warning 505" is a warning. A warning is not an error! It is user information about something not being optimal yet (but code still executing) while on the other hand error breaks AFL execution. AB even displays word warning 505 so why do you say error while AB says warning? Please try to understand the differences.

And please be detailed next time instead of making people waste time on guessing. As you can see you were clearly talking about/looking for something else.


There should be a disclaimer also otherwise tomorrow someone will say i'm using 1e-1000 and its not working :smiley:

Depending on the AB version, one is subject to limit of single and double precision floats after which due to rounding or conversion error the number returned is 0.