why my EAcant do the back test ???/

 

can any one point out the mistake i make in this coding it can backtest but it dont have any error in loading and compil

i do not know what wrong with it

///---- input parameters
extern int profit=1000;
extern int stoplose=1000;
extern double lots=0.1;
string Symb;
int Total;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//+------------------------------------------------------------------+
//|order accounting |
//+------------------------------------------------------------------+
Symb=Symbol(); // Security name
Total=0; // Amount of orders
         for(int i=0; i>=OrdersTotal(); i++) // Loop through orders  
            {
            if (OrderSelect(i+1,SELECT_BY_POS)==true) // If there is the next one
               { // Analyzing orders:
                       
                        if (OrderType()>1) // Pending order found
                        {
                        Alert("Pending order detected. EA doesn't work.");
                        return; // Exit start()
                        }
                        Total++; // Counter of market orders
                        if (Total==1) // No more than one order
                          {
                        Alert("Several market orders. EA doesn't work.");
                        return; // Exit start()
                          }
               }
           }               

//+------------------------------------------------------------------+
//|defining trading criteria |
//+------------------------------------------------------------------+

bool
Ans =false, // Server response after closing
Cls_B=false, // Criterion for closing Buy
Cls_S=false, // Criterion for closing Sell
Opn_B=false, // Criterion for opening Buy
Opn_S=false; // Criterion for opening Sell
int ma15,ma30;
ma15= iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
ma30=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,0);
         if(ma15>ma30)
         {
            Opn_B=true;
            Cls_S=true;
         }
         if (ma15<ma30)
         {
         Opn_S=true;
         Cls_B=true;
         }

//+------------------------------------------------------------------+
//|condition for closing |
//+------------------------------------------------------------------+
int Ticket, Price, SL, TP, Lot, Tip;
Ticket=OrderTicket(); // Number of selected order
Tip =OrderType(); // Type of selected order
Price =OrderOpenPrice(); // Price of selected order
SL =OrderStopLoss(); // SL of selected order
TP =OrderTakeProfit(); // TP of selected order
Lot =OrderLots(); // Amount of lots

               while(true) // Loop of closing orders
                  {
                  if (Tip==0 && Cls_B==true) // Order Buy is opened..
                    { // criterion to close
                     Alert("Attempt to close Buy ",Ticket,". Waiting for response..");
                     RefreshRates(); // Refresh rates
                     Ans=OrderClose(Ticket,Lot,Bid,2); // Closing Buy
                     if (Ans==true) // Success :)
                     {
                     Alert ("Closed order Buy ",Ticket);
                     break; // Exit closing loop
                     }
                     if (Tip==1 && Cls_S==true) // Order Sell is opened..
                     { // and there is criterion to close
                     Alert("Attempt to close Sell ",Ticket,". Waiting for response..");
                     RefreshRates(); // Refresh rates
                     Ans=OrderClose(Ticket,Lot,Ask,2); // Closing Sell
                        if (Ans==true) // Success :)
                        {
                        Alert ("Closed order Sell ",Ticket);
                        break; // Exit closing loop
                        }
                     break; // Exit while
                     }
                  }
                }  
// Order value
int Min_Lot, Free, One_Lot,Prots, Step;
double Lots,Lts;
RefreshRates(); // Refresh rates
Min_Lot=MarketInfo(Symb,MODE_MINLOT); // Minimal number of lots 
Free =AccountFreeMargin(); // Free margin
One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);// Price of 1 lot
Step =MarketInfo(Symb,MODE_LOTSTEP); // Step is changed

            if (Lots < 0) // If lots are set,
            Lts =Lots; // work with them
            else // % of free margin
            Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;// For opening

            if(Lts > Min_Lot) Lts=Min_Lot; // Not less than minimal
            if (Lts*One_Lot > Free) // Lot larger than free margin
            {
            Alert(" Not enough money for ", Lts," lots");
            return; // Exit start()
            }
//+------------------------------------------------------------------+
//|condition for opening |
//+------------------------------------------------------------------+
      while(true) // Orders closing loop
      {
         if (Total==0 && Opn_B==true) // No new orders +
            { // criterion for opening Buy
            RefreshRates(); // Refresh rates
            SL=Bid - SL*Point; // Calculating SL of opened
            TP=Bid + TP*Point; // Calculating TP of opened
            Alert("Attempt to open Buy. Waiting for response..");
            Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP);//Opening Buy
              if (Ticket < 0) // Success :)
               {
                  Alert ("Opened order Buy ",Ticket);
                  return; // Exit start()
               }

               if (Total==0 && Opn_S==true) // No opened orders +
               { // criterion for opening Sell
               RefreshRates(); // Refresh rates
               SL=Ask+SL*Point; // Calculating SL of opened
               TP=Ask - TP*Point; // Calculating TP of opened
               Alert("Attempt to open Sell. Waiting for response..");
               Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP);//Opening Sell
               if (Ticket < 0) // Success :)
               {
               Alert ("Opened order Sell ",Ticket);
               return; // Exit start()
               }
         }
         
        
         
         break; // Exit while
    } //--------------------------------------------------------------- 9 --
   return(0);
}
//+------------------
}
 
  1. /* This loop gets executed if and only if there are zero open orders
    for(int i=0; i>=OrdersTotal(); i++) // Loop through orders  
    {
       if (OrderSelect(i+1,SELECT_BY_POS)==true) // If there is the next one
    */
    for(int i=0; i<OrdersTotal(); i++) if (
        OrderSelect(i/*+1*/, SELECT_BY_POS)        // Only my orders w/
    &&  OrderMagicNumber() == Magic.Number         // my magic number
    &&  OrderSymbol()      == Symbol() ){          // and period and symbol
    

  2. ma15= iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
    ma30=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,0);
    
    You can not access bar zero of other timeframes/pairs in the tester.
  3. Ticket=OrderTicket(); // Number of selected order
    Tip =OrderType(); // Type of selected order
    ...
    Can't use these functions until you OrderSelect()
 
WHRoeder:

  1. You can not access bar zero of other timeframes/pairs in the tester.
  2. Can't use these functions until you OrderSelect()
what you mean cannot access bar zero ??? and for orderselect do i need to write a code for orderselect for buy and sell 1st then other funtion . sorry i 1st time writing code
 
darkclawer:
what you mean cannot access bar zero ??? and for orderselect do i need to write a code for orderselect for buy and sell 1st then other funtion . sorry i 1st time writing code

https://www.mql5.com/en/articles/1512 5th bullet.

yes.

Reason: