Author: rem
Profit factor:
0.63
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
3 Views
0 Downloads
0 Favorites
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.

Profitability Reports

NZD/USD Oct 2024 - Jan 2025
0.55
Total Trades 487
Won Trades 138
Lost trades 349
Win Rate 28.34 %
Expected payoff -20.18
Gross Profit 12206.00
Gross Loss -22032.00
Total Net Profit -9826.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.58
Total Trades 361
Won Trades 95
Lost trades 266
Win Rate 26.32 %
Expected payoff -26.66
Gross Profit 13192.00
Gross Loss -22818.00
Total Net Profit -9626.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.76
Total Trades 785
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -10.32
Gross Profit 25125.00
Gross Loss -33230.00
Total Net Profit -8105.00
-100%
-50%
0%
50%
100%

Comments