A quick mathematical problem

 

Hello, traders!

This is my first forum post on this forum but I really need this one. I'm having pretty peculiar trouble with the function MathAbs int MQL4. It returns a NEGATIVE number. I have two edits of the particular line and it still returns negative. Here it is.

The original one:

LotSize = NormalizeDouble(OrderLots()*MathAbs((OrderTakeProfit()-OrderStopLoss())/(ATR/Point)),2);

And after getting negative by this one I used MathAbs one more time:

LotSize = MathAbs(NormalizeDouble(OrderLots()*MathAbs((OrderTakeProfit()-OrderStopLoss())/(ATR/Point)),2));

The later should in theory make an absolute of the resulting number (although it SHOULD be absolute too). To my rising anger the result is still negative.

Any help will be much appreciated, thanks in advance! 

 
  1. The result is not negative. Your problem is elsewhere. Print your variables.
  2. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
 
Георги Дичев:

Hello, traders!

This is my first forum post on this forum but I really need this one. I'm having pretty peculiar trouble with the function MathAbs int MQL4. It returns a NEGATIVE number. I have two edits of the particular line and it still returns negative. Here it is.

The original one:

And after getting negative by this one I used MathAbs one more time:

The later should in theory make an absolute of the resulting number (although it SHOULD be absolute too). To my rising anger the result is still negative.

Any help will be much appreciated, thanks in advance! 

Hi Buddy


I have a very similar issue - i tried everything ... eventually i used MathAbs for the overall formula.

My parameters were one positive and one the result of a difference.

Initially I was doing something like: ArrVolPosTrigger[i] = 1000*PositionTrigger/(MacdUp-MacdDn) - and the result was sometimes (not even consistently negative).

PositionTrigger is just an addition of parameters. Should never be negative and isn't - i checked them with Alert.


My only workaround to date is this: ArrVolPosTrigger[i] = MathAbs(1000*PositionTrigger/(MacdUp-MacdDn)).

Are you saying that not even the workaround works for you ?


Regards

CB

 
CB:

Hi Buddy


I have a very similar issue - i tried everything ... eventually i used MathAbs for the overall formula.

My parameters were one positive and one the result of a difference.

Initially I was doing something like: ArrVolPosTrigger[i] = 1000*PositionTrigger/(MacdUp-MacdDn) - and the result was sometimes (not even consistently negative).

PositionTrigger is just an addition of parameters. Should never be negative and isn't - i checked them with Alert.


My only workaround to date is this: ArrVolPosTrigger[i] = MathAbs(1000*PositionTrigger/(MacdUp-MacdDn)).

Are you saying that not even the workaround works for you ?


Regards

CB

Prove it. Show the code, the values, the logs.
Reason: