Inquiry on Backtester & Optimization

To add comments, please log in or register
Ibex Thales
99
Ibex Thales  

Greetings!

Would just like to ask why when I backtest using the parameters of optimization, the backtest results are radically different from when I optimized it?

Did I miss something? Isn't it that optimization is akin to a backtest en masse?

Spread is fixed. Basically all i did is uncheck the "Optimization" option, then edit the code into the desired optimization result.

My code looks like this:

#property strict

#include <stderror.mqh>
#include <stdlib.mqh>

extern int     MagicNumber = 10001;
extern double  Lots        = 0.1;
extern int     Slippage    = 3;
extern int     BollTime    = 60;
extern int     BollDev     = 3;

bool     result;
double   Basis;
double   BollUpper_Prev;
double   BollMid_Prev;
double   BollLower_Prev;
double   BollUpper_Curr;
double   BollMid_Curr;
double   BollLower_Curr;

// Buy @ Cross up; Sell @ Cross down Upper Mid or Cross up Upper or Mid vs MA vs Close
// Buy Open @ Cross Up of Lower

void OnTick()
{
   Basis          = Close[1];
   BollUpper_Prev = iBands(NULL,0,BollTime,BollDev,0,PRICE_CLOSE,MODE_UPPER,2);
   BollMid_Prev   = iBands(NULL,0,BollTime,BollDev,0,PRICE_CLOSE,MODE_MAIN,2);
   BollLower_Prev = iBands(NULL,0,BollTime,BollDev,0,PRICE_CLOSE,MODE_LOWER,2);
   BollUpper_Curr = iBands(NULL,0,BollTime,BollDev,0,PRICE_CLOSE,MODE_UPPER,1);
   BollMid_Curr   = iBands(NULL,0,BollTime,BollDev,0,PRICE_CLOSE,MODE_MAIN,1);
   BollLower_Curr = iBands(NULL,0,BollTime,BollDev,0,PRICE_CLOSE,MODE_LOWER,1);

// Open conditions
   if(OrdersTotal()==0)
   {
      if(Basis < BollLower_Prev && 
         Basis > BollLower_Curr)
      {
         result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,NULL,MagicNumber,0,Blue);
      }
      if(Basis > BollUpper_Prev && 
         Basis < BollUpper_Curr)
      {
         result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,NULL,MagicNumber,0,Red);         
      }
   }   

// Close conditions
   if(OrdersTotal()>0)
   {
         if(!OrderSelect(0, SELECT_BY_POS, MODE_TRADES))
         Print("Error select of order: "+string(ErrorDescription(GetLastError())));

         if((OrderType()==OP_BUY) && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber))
         {
            if(Basis > BollUpper_Prev && 
               Basis < BollUpper_Curr)
            {
               if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red))
               Print("Error close of buy order: "+string(ErrorDescription(GetLastError())));
            }
         }
      else
      {
         if((OrderType()==OP_SELL) && (OrderSymbol()==Symbol()) && (OrderMagicNumber()==MagicNumber))
         {
            if(Basis < BollLower_Prev && 
               Basis > BollLower_Curr)
            {
               if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Blue))
               Print("Error close of sell order: "+string(ErrorDescription(GetLastError())));
            }
         }
      }
   }
}


For the record, I read, reread, and backread but to no avail.

Hope you can clarify me with this.

Thank you!

To add comments, please log in or register