MQL4 bad math issues - page 2

 
Irtron:
kvibert:
kvibert:
kvibert:
wackena:

If it is a rounding problem, try this.

    ma_fast1=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,1),Digits);
    ma_fast2=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,2),Digits);
    ma_fast3=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,3),Digits);
    ma_slow1=NormalizeDouble(iMA(NULL,0,ev_SlowMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,1),Digits);
    ma_slow2=NormalizeDouble(iMA(NULL,0,ev_SlowMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,2),Digits);
    ma_slow3=NormalizeDouble(iMA(NULL,0,ev_SlowMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,3),Digits);




I tried your suggestion and it worked like a charm! My faith in MQL4 has been retsored. Actually I had little doubt it would turn out to be a user error.

This change took care of both problems.

new test results

17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: CFO FIRST TICK
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: CHECK FOR OPEN
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: ma_fast1 = 2.0381 ma_fast2 = 2.0377 ma_fast3 = 2.0371
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: ma_slow1 = 2.0317 ma_slow2 = 2.0312 ma_slow3 = 2.0307
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: ma_D1 = 0.0064 ma_D2 = 0.0065 ma_D3 = 0.0064
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: CFO - SELL
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: open #8 sell 0. 10 GBPUSD at 2.0560 sl: 2.0760 tp: 2.0160

Wakena, thanks very much for taking up my issue so quickly!

Great!
Why to get stuck with precision stretched to enormous number of Digits decimals?
You can make it even better - limit it to 0.

ma_fast1=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,1),0)
The only issue in your initial post was rounding error while printing the results. Print() rounds doubles to 4 digits.
The calculations themselves were perfectly fine.

I have 25 years experience in software programming and analysis.

Wakena, thanks very much for taking up my issue so quickly!

My congratulations.

Irtron,

thanks very much for the further clarification, how will '0' do? I am still having some rounding issue in a few spots and I will try your suggestion. Where can I find the library you refered to earlier?

Its ok to throw my experience back in my face I probably deserve it for even metioning it, I'm pleased to know it makes you feel good. And by the way I thanked you before I thanked Wakena, but I guess you missed that.

 
Irtron:
kvibert:
kvibert:
kvibert:
wackena:

If it is a rounding problem, try this.

    ma_fast1=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,1),Digits);
    ma_fast2=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,2),Digits);
    ma_fast3=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,3),Digits);
    ma_slow1=NormalizeDouble(iMA(NULL,0,ev_SlowMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,1),Digits);
    ma_slow2=NormalizeDouble(iMA(NULL,0,ev_SlowMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,2),Digits);
    ma_slow3=NormalizeDouble(iMA(NULL,0,ev_SlowMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,3),Digits);




I tried your suggestion and it worked like a charm! My faith in MQL4 has been retsored. Actually I had little doubt it would turn out to be a user error.

This change took care of both problems.

new test results

17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: CFO FIRST TICK
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: CHECK FOR OPEN
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: ma_fast1 = 2.0381 ma_fast2 = 2.0377 ma_fast3 = 2.0371
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: ma_slow1 = 2.0317 ma_slow2 = 2.0312 ma_slow3 = 2.0307
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: ma_D1 = 0.0064 ma_D2 = 0.0065 ma_D3 = 0.0064
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: CFO - SELL
17:44:34 2007.07.25 04:00 MA FAST SLOW DEVIATION 1.1D GBPUSD,H4: open #8 sell 0. 10 GBPUSD at 2.0560 sl: 2.0760 tp: 2.0160

Wakena, thanks very much for taking up my issue so quickly!

Great!
Why to get stuck with precision stretched to enormous number of Digits decimals?
You can make it even better - limit it to 0.

ma_fast1=NormalizeDouble(iMA(NULL,0,ev_FastMovingPeriod,0,MODE_SMMA,PRICE_CLOSE,1),0)
The only issue in your initial post was rounding error while printing the results. Print() rounds doubles to 4 digits.
The calculations themselves were perfectly fine.

I have 25 years experience in software programming and analysis.

Wakena, thanks very much for taking up my issue so quickly!

My congratulations.


Your suggestion to limit it to zero did not work, was that was tthe point?

K

.

 
kvibert:
Your suggestion to limit it to zero did not work, was that was tthe point?
Pure sarcasm, sorry.

I'm curious why rounded to integer result is not acceptable while it's ok if you round it to 4 digits? :)

Here is an example of printing double with arbitrary precision
#include <stdlib.mqh>
 
int start()
{
    Print(DoubleToStrMorePrecision(13./7., 16));
    return (0);
}

PS
Why not to cut the long-winded quotes of previous comments in your replies.
Reason: