testEA3





//+------------------------------------------------------------------+
//|                                                       testEA3.mq4 |
//|                                                              rem |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "rem"
#property link      ""

extern double Lots = 1;

int start()
  {
   int cnt, ticket, total;

   total=OrdersTotal();
   
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(Close[1] > Close[2])
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,"testEA3",16384,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(Close[1] < Close[2])
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,0,0,"testEA3",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
     
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be Closed?
            if(Close[1] < Close[2])
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,0,Violet); // Close position
                 
                 // + open a new one
                 ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,0,0,"testEA2",16384,0,Red);
                 if(ticket>0)
                  {
                     if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
                  }
                 else Print("Error opening SELL order : ",GetLastError()); 
                 return(0); // exit
                }
 
           }
         else // go to short position
           {
            // should it be Closed?
            if(Close[1] > Close[2])
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,0,Violet); // Close position
            
               // + open a new one  
               ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,"testEA2",16384,0,Green);
               if(ticket>0)
                 {
                  if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
                 }
               else Print("Error opening BUY order : ",GetLastError()); 
               return(0); // exit
              }
 
           }
        }
     }
   return(0);
  }
// the end.



Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself

Other Features:


BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.66 Total Net Profit:-9769.90

BackTest : EURUSD on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.38 Total Net Profit:-9941.30

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:0.70 Total Net Profit:-9743.80

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.54 Total Net Profit:-9678.90

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.42 Total Net Profit:-10001.54

BackTest : USDCHF on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.69 Total Net Profit:-5484.81

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.58 Total Net Profit:-7035.96

Request Backtest for testEA3


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: