Who's confused, my EA or me?

 

These 2 EA basically the same, using EMA crossover. I backtested them on GBPUSD using IBFX mini demo account for October only (till the 20). EA_1 gained almost 50%, and EA_2 lost nearly 100%.

Problem is: I manually check trades from both EA (first to ten, not all of them), and only the first trade (from both) did exactly as I wanted them. The rest were triggered not even close from the setup. And both passed many crossovers.

My questions:

Does historical data from IBFX are so different than the data they put on their chart? (so it's their mistake, not my EAs).

or

My EA coding are so absurd that they did exactly what I don't want them to do, with so different results. (The mistake is on me, not anybody or anything else).

Thank you all for your help.

Files:
ea_1.mq4  10 kb
ea_2.mq4  8 kb
 

hi

just do a visual backtest watch how they trade.i lke visual

 

I think you've run into the pot-hole MetaQuotes created recently by changing the tester to recompute the intra-bar ticks anew at every test run. If your EA, as it does, depends on these ticks, then you cannot expect two runs even of the same EA on the same backtest data to be the same.

But perhaps you would fare better with an "open bar only" time filter:

static datetime time = 0;

if ( Time[ 0 ] == time ) return( 0 );

time = Time[ 0 ];

inserted at the beginning of the start() function. Then you should also rather

peep at the bars 1, 2 and 3 of iMA instead of 0, 1, 2 (since bar 0 is just about

started and far from complete).

 

Why not using closed bars only? MA crossovers are closed bar MA crosses otherwise its re-drawing.

double x1=iMA(NULL,PERIOD_H1,24,0,MODE_EMA,PRICE_MEDIAN,0);

double y1=iMA(NULL,PERIOD_H1,28,0,MODE_EMA,PRICE_MEDIAN,0);

Yep! Thats the problem. Change 0 to 1 in the end so it will look like this:

double x1=iMA(NULL,PERIOD_H1,24,0,MODE_EMA,PRICE_MEDIAN,1);

double y1=iMA(NULL,PERIOD_H1,28,0,MODE_EMA,PRICE_MEDIAN,1);

and change the next MA crosses to 2 and 3 respectively.

Ralph you were correct here.

But its quite a funny way of using MA cross - "crossed up = true" A different way would be checking last 2 bars (1 bar back, 2 bars back) and seeing if they crossed.

And yes, your program seems absurd I use this:

if(lastMA<lastMA2) {

if(nowMA>nowMA2)

cross=1; } // cross up

else if(lastMA>lastMA2) {

if(nowMA<nowMA2)

cross=-1; } // cross down

Instead of huge blocks of code. Hope this helps

Reason: