This forum is in read-only mode now. You may discuss your questions on forums of MQL4.community and MQL5.community

Possible workaround for people with backtesting problems


Back to topics list
avatar
129
Vooch 2005.07.15 11:07 
I started fooling around with this code tonight in an effort to reduce mutliple orders going through at the same time when backtesting and to fix the problem where it keeps ordering stuff at an old price and selling at a newer price.

This seems to do a good job slowing down the order flow and is meant to fix/hack the problem I'm having here: "Backtesting problems with 4-hour charts" .

The bad thing is there's a performance hit from using this.

The good thing is that it might give me more accurate results when backtesting.

////////////////////////////////////////////////////////////////
// DO NOT PLACE AN ORDER IF WE JUST CLOSED AN ORDER WITHIN Period() MINUTES AGO
datetime orderclosetime;
int TheHistoryTotal=HistoryTotal();
string rightnow;
int rightnow2;
int difference;
for(cnt=0;cnt<TheHistoryTotal;cnt++) {
    if(cnt!=0) {
        if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true)
        {
            orderclosetime=OrderCloseTime();
            rightnow=Year()+"-"+Month()+"-"+Day()+" "+Hour()+":"+Minute()+":"+Seconds();            
            rightnow2=StrToTime(rightnow);
            difference=rightnow2-orderclosetime;
            if(Period()*60>difference) {
                openbuyorders=99999;
                opensellorders=99999;
            }
        }
    }
}
////////////////////////////////////////////////////////////////

if (openbuyorders<1 && opensellorders<1) {
//  code to calculate stuff and buy/sell stuff
}

Back to topics list  
Download MetaTrader 5 (450 Kb, web installer) — a new terminal for financial markets