Question about dedicated back testing

 
Hi

i've got a problem in undestanding the backtesting function of mt4 and i hope you can help me.


Till yet i tried to backtest my EA using the normal backtest function of metatrader4.

But now i have to test a big amount of different property settings.
So the problem is, that MT4 is to slow to test all of the property settings in short time.

Then i had the idea to write my own test function in C++, so i did.

So i exported the data from MT and used it for my own BT function.

I used the data for the first tick in each bar.

But i have calculation errors on things like:

- StopSell Function
- TakeProfit Function
- and how the Profit is calculated exactly.

in the end the results of my test calculation and the MT4- calculation don't match.
There is maybe something wrong with my code, or MT tries to disturb the results i don't know.

I hope You can help me with this.

thx

Here is my c++ code how i calculate my TP,SL and Profit
//////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
bool OrderClose( int type, double lots, double price, int slippage, int Color)
{
    //Calculate profit


    double profit = 0;

    if(o.type == OP_BUY)
    {
        profit = ((price - o.price) * lots) * 100000;// / Point();

        if(DEBUG_LEVEL) printf("close buy, profit: %f %i %i\n", profit, type, index - o.barnr);
    } else if(o.type == OP_SELL)
    {
        profit = ((o.price - price) * lots) * 100000;// / Point();
        if(DEBUG_LEVEL) printf("close sell, profit: %f %i %i\n", profit, type, index - o.barnr);
    }

    if(profit > 0)
    orders_profit++;
    else if(profit < 0)
    orders_loss++;

    free_margin += profit;

    o.type = -1;
    o.tr = type;
    o.barnr = 0;
    //slot_1_Index = -1;
    //slot_1_Type = -1;
    return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CheckStopLossTakeProfit()
{
//this function checks if its nessecary to close the order on sl or tp
    double current = course[index].close;
    double order = o.price;

    double st = (StopLoss)/100000.0;
    double tp = (TakeProfit)/100000.0;

    double close = course[index].close;
    double low = course[index].low;
    double high = course[index].high;

    if(o.type == OP_BUY)
    {
        // close gut, Ask/Bid besser

        //if((current - st) <= order) ||//StopLoss
        //if((order - Bid()) >= st)
        //if((order - st) <= low)
        if(o.sl >= high)
        //if((order - course[index].low) >= st)
        //if((order - current)* >= StopLoss)
        {
            //OrderClose(1,OrderLots(),Bid(),3,Red);
            if(o.type != -1)
            OrderClose(1,OrderLots(),order - st,3,Red);
        }
        //if((current + tp) >= order) // TakeProfit
        //if((order + tp) >= high)
        if(o.tp <= low)
        //if((course[index].high - order) >= tp)
        {
            //OrderClose(1,OrderLots(),Bid(),3,Red);
            if(o.type != -1)
            OrderClose(1,OrderLots(),order + tp,3,Red);
        }
    } else if(o.type == OP_SELL)
    {
        //if((current + st) >= order) || //StopLoss
        //if((course[index].high - order) >= st)
        //if((order + st) >= high)
        if(o.tp <= low)
        {
            //OrderClose(1,OrderLots(),Ask(),3,Blue);
            if(o.type != -1)
            OrderClose(1,OrderLots(),order + st,3,Blue);
        }
        //if((current - tp) <= order) // TakeProfit
        //if((order - course[index].low) >= tp)
        //if((order - tp) < low)
        if(o.sl >= high)
        {
            //OrderClose(1,OrderLots(),Ask(),3,Blue);
            if(o.type != -1)
            OrderClose(1,OrderLots(),order - tp,3,Blue);
        }
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////
Reason: