Beginner issues! I have no errors when compiling the codes in the editor, but it fails to run in the back test systemof Metatrader4

 

Can anyone please help? The codes are attached below:

//+------------------------------------------------------------------+
//|                                               Tim Lo trading.mq4 |
//|                                              Copyright 2015, Tim |
//|                                             yau1232b@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Tim"
#property link      "yau1232b@hotmail.com"
#property version   "1.00"
#property description "Please e-mail me if you have any enquiries"
#property strict
int highnum = 0;
int lownum = 0;
int bidprices[20];
int askprices[20];
int prices[20];
bool up = false;
bool down = false;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 
  
   for(int i = 0; i < 20; i++){
  
   bidprices[18-i] = bidprices[19-i];
  
   }
  
   for(int i = 0; i < 20; i++){
  
   askprices[18-i] = askprices[19-i];
  
   }
  
   bidprices[0] = Bid;
   askprices[0] = Ask;
  
   for(int i = 0; i < 20; i++){
  
   prices[i] = (bidprices[i] + askprices[i])/2;
  
   }
  
   for(int i = 0; i <20; i++){
  
   highnum = 0;
   lownum = 0;
  
   if(prices[i] > prices[i+1]){
   highnum++;
   }
  
   if(prices[i] < prices[i+1]){
   lownum++;
   }
  
   if(highnum>15){
   for (int g = OrdersTotal()-1; g >= 0; g--)
   {
      if ( OrderSelect(g, SELECT_BY_POS) )
      { 
         bool closeorder = false;
         if (OrderType() == OP_SELL)
           closeorder = OrderClose(g,1,Ask,3,clrGreen);
           if( closeorder = true )
           {Print("Order closed");
           }
           else{
           Print("Order close filed, error # ", GetLastError() );
           }
      }
   }
   if(up){
   }
   else{
   int TicketNumberbuy = 0;
   TicketNumberbuy = OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"Buy Order",1,0,clrGreen);
   Print("Buy Order");
   up = true;
   down = false;
   if( TicketNumberbuy > 0 )
   {
   Print("Order placed # ", TicketNumberbuy);
   }
else
   {
   Print("Order Send failed, error # ", GetLastError() );
  
   }
   }
   }
  
   if(lownum>15){
     for (int g = OrdersTotal()-1; g >= 0; g--)
   {
      if ( OrderSelect(g, SELECT_BY_POS) )
      {
         bool closeorder = false;
         if (OrderType() == OP_BUY)
           closeorder = OrderClose(g,1,Bid,3,clrRed);
           if( closeorder = true )
           {Print("Order closed");
           }
           else{
           Print("Order close filed, error # ", GetLastError() );
           }
 
      }
   }
   if(down){
   }
   else{
   int TicketNumbersell = 0;
   TicketNumbersell = OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"Sell Order",2,0,clrRed);
   Print("Sell Order");
   up = false;
   down = true;
   if( TicketNumbersell > 0 )
   {
   Print("Order placed # ", TicketNumbersell);
   }
else
   {
   Print("Order Send failed, error # ", GetLastError() );
  
   }  
   }
   }
  
   
   }

  }
//+------------------------------------------------------------------+
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.