Author: Coders Guru
Profit factor:
4.50
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Moving average indicator
6 Views
0 Downloads
0 Favorites
EMA-CROSS
//+------------------------------------------------------------------+
//|                                                    EMA_CROSS.mq4 |
//|                                                      Coders Guru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TODO: Add Money Management routine                               |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link      "http://www.forex-tsd.com"
//---- input parameters
extern double    TakeProfit=130;
extern double    StopLoss = 100;
extern double    Lots=1;
extern double    TrailingStop=20;
extern int ShortEma = 12;
extern int LongEma = 20;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
int Crossed (double line1 , double line2)
   {
      static int last_direction = 0;
      static int current_direction = 0;
      
      //Don't work in the first load, wait for the first cross!
      static bool first_time = true;
      if(first_time == true)
      {
         first_time = false;
         return (0);
      }
      
      if(line1>line2)current_direction = 1; //up
      if(line1<line2)current_direction = 2; //down
      if(current_direction != last_direction) //changed 
      {
            last_direction = current_direction;
            return (last_direction);
      }
      else
      {
            return (0); //not changed
      }
   }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 
   int cnt, ticket, total;
   double SEma, LEma;
   
   
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
        
   SEma = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0);
   LEma = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_CLOSE,0);
   
   
   static int isCrossed  = 0;
   isCrossed = Crossed (LEma,SEma);
   
   total  = OrdersTotal(); 
   if(total < 1) 
     {
       if(isCrossed == 1)
         {
            //ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"EMA_CROSS",12345,0,Green);
            ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"EMA_CROSS",12345,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);
         }
         if(isCrossed == 2)
         {
            //ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"EMA_CROSS",12345,0,Red);
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"EMA_CROSS",12345,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);
     }
     
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      //OrderPrint();
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
           
           /* REMOVED - Trailling stop only close
           if(isCrossed == 2)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
           */
           
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            
            /* REMOVED - Trailling stop only close
            if(isCrossed == 1)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            */
            
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
 

Profitability Reports

GBP/USD Jul 2025 - Sep 2025
0.61
Total Trades 185
Won Trades 110
Lost trades 75
Win Rate 59.46 %
Expected payoff -15.62
Gross Profit 4611.00
Gross Loss -7500.00
Total Net Profit -2889.00
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.30
Total Trades 239
Won Trades 111
Lost trades 128
Win Rate 46.44 %
Expected payoff -24.21
Gross Profit 2526.12
Gross Loss -8312.39
Total Net Profit -5786.27
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
37.20
Total Trades 2094
Won Trades 2026
Lost trades 68
Win Rate 96.75 %
Expected payoff 117.57
Gross Profit 252994.00
Gross Loss -6800.00
Total Net Profit 246194.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.70
Total Trades 152
Won Trades 104
Lost trades 48
Win Rate 68.42 %
Expected payoff -9.35
Gross Profit 3379.00
Gross Loss -4800.00
Total Net Profit -1421.00
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.36
Total Trades 91
Won Trades 53
Lost trades 38
Win Rate 58.24 %
Expected payoff -19.05
Gross Profit 959.30
Gross Loss -2692.73
Total Net Profit -1733.43
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.26
Total Trades 122
Won Trades 66
Lost trades 56
Win Rate 54.10 %
Expected payoff -33.83
Gross Profit 1473.00
Gross Loss -5600.00
Total Net Profit -4127.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.73
Total Trades 184
Won Trades 134
Lost trades 50
Win Rate 72.83 %
Expected payoff -7.32
Gross Profit 3653.00
Gross Loss -5000.00
Total Net Profit -1347.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.31
Total Trades 106
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -28.69
Gross Profit 1359.00
Gross Loss -4400.00
Total Net Profit -3041.00
-100%
-50%
0%
50%
100%

Comments