Profit factor:
0.62
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Moving average indicatorIndicator of the average true range
Miscellaneous
It sends emails
9 Views
0 Downloads
0 Favorites
CrossMA
//+------------------------------------------------------------------+
//|                                                      CrossMa.mq4 |
//|                      Copyright © 2005, George-on-Don             |
//|                                       http://www.forex.aaanet.ru |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#include <stderror.mqh>
 
#define MAGICMA  20050610
 
extern double Lots               = 0.1;
extern double MaximumRisk        = 0.02;
extern double DecreaseFactor     = 3;
extern double MovingPeriod       = 12;
extern double MovingShift        = 0;
extern double MovingPeriod1      = 4;
extern double AtrPer             = 6;
extern bool   SndMl              = True ;
//+------------------------------------------------------------------+
//| Ðàñ÷åò îòêðûòèÿ ïîçèöèè                                          |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
//+------------------------------------------------------------------+
//| Ðàñ÷åò îïòèìàëüíîé âåëè÷èíû ëîòà                                 |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//---- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
         //----
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//---- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Ïðîâåðêà äëÿ îòêðûòèÿ ïîçèöèè ñ ïåðâûì òèêîì íîâîãî áàðà.        |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double mas;
   double maf;
   double mas_p;
   double maf_p;
   double Atr;
   int    res;
   string sHeaderLetter;
   string sBodyLetter;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
   mas=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,1); // äèííûé ìóâèíã 12
   maf=iMA(NULL,0,MovingPeriod1,MovingShift,MODE_SMA,PRICE_CLOSE,1);// êîðîòêèé ìóâèíã 4
   mas_p=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,2); // äèííûé ìóâèíã 12
   maf_p=iMA(NULL,0,MovingPeriod1,MovingShift,MODE_SMA,PRICE_CLOSE,2);// êîðîòêèé ìóâèíã 4
   Atr = iATR(NULL,0,AtrPer,0);
 //---- Óñëîâèå ïðîäàæè
   if(maf<mas && maf_p>=mas_p)  
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Ask+Atr,0,"",MAGICMA,0,Red);
       if (SndMl == True && res != -1) 
         {
         sHeaderLetter = "Operation SELL by" + Symbol()+"";
         sBodyLetter = "Order Sell by"+ Symbol() + " at " + DoubleToStr(Bid,4)+ ", and set stop/loss at " + DoubleToStr(Ask+Atr,4)+"";
         sndMessage(sHeaderLetter, sBodyLetter);
         }
      return;
     }
//---- Óñëîâèå ïîêóïêè
   if(maf>mas && maf_p<=mas_p)  
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Bid-Atr,0,"",MAGICMA,0,Blue);
      if ( SndMl == True && res != -1)
      { 
      sHeaderLetter = "Operation BUY at" + Symbol()+"";
      sBodyLetter = "Order Buy at"+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and set stop/loss at " + DoubleToStr(Bid-Atr,4)+"";
      sndMessage(sHeaderLetter, sBodyLetter);
      }
      return;
     }
//----
  }
//+------------------------------------------------------------------+
//| ÏÐîâåðêà äëÿ çàêðûòèÿ îòêðûòîé ïîçèöèè                           |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double mas;
   double maf;
   double mas_p;
   double maf_p;
   string sHeaderLetter;
   string sBodyLetter;
   bool rtvl;
//---- 
   if(Volume[0]>1) return;
//----  
   mas=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,1); // äèííûé ìóâèíã 12
   maf=iMA(NULL,0,MovingPeriod1,MovingShift,MODE_SMA,PRICE_CLOSE,1);// êîðîòêèé ìóâèíã 4
   mas_p=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,2); // äèííûé ìóâèíã 12
   maf_p=iMA(NULL,0,MovingPeriod1,MovingShift,MODE_SMA,PRICE_CLOSE,2);// êîðîòêèé ìóâèíã 4
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //----  
      if(OrderType()==OP_BUY)
        {
         if(maf<mas && maf_p>=mas_p) rtvl=OrderClose(OrderTicket(),OrderLots(),Bid,3,Lime);
            if ( SndMl == True && rtvl != False )
            {
            sHeaderLetter = "Operation CLOSE BUY at" + Symbol()+"";
            sBodyLetter = "Close order Buy at"+ Symbol() + " for " + DoubleToStr(Bid,4)+ ", and finish this Trade";
            sndMessage(sHeaderLetter, sBodyLetter);
            }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(maf>mas && maf_p<=mas_p) rtvl=OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime);
         if ( SndMl == True && rtvl != False ) 
         {
         sHeaderLetter = "Operation CLOSE SELL at" + Symbol()+"";
         sBodyLetter = "Close order Sell at"+ Symbol() + " for " + DoubleToStr(Ask,4)+ ", and finish this Trade";
         sndMessage(sHeaderLetter, sBodyLetter);
         }
         break;
        }
     }
//----
  }
  
//--------------------------------------------------------------------
// ôóíêöèÿ îòïðàâêè ññîáùåíèÿ îá îòðûòèè èëè çàêðûòèè ïîçèöèè
//--------------------------------------------------------------------
void sndMessage(string HeaderLetter, string BodyLetter)
{
   int RetVal;
   SendMail( HeaderLetter, BodyLetter );
   RetVal = GetLastError();
   if (RetVal!= ERR_NO_MQLERROR) Print ("Îøèáêà, ñîîáùåíèå íå îòïðàâëåíî: ", ErrorDescription(RetVal));
}
//+------------------------------------------------------------------+
//| Ìàéí ôóíêöèÿ                                                     |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<25 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//----
  }
//+------------------------------------------------------------------+

Profitability Reports

USD/CAD Jul 2025 - Sep 2025
0.40
Total Trades 209
Won Trades 34
Lost trades 175
Win Rate 16.27 %
Expected payoff -3.41
Gross Profit 475.78
Gross Loss -1189.36
Total Net Profit -713.58
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.70
Total Trades 206
Won Trades 42
Lost trades 164
Win Rate 20.39 %
Expected payoff -2.05
Gross Profit 968.30
Gross Loss -1390.20
Total Net Profit -421.90
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.60
Total Trades 214
Won Trades 49
Lost trades 165
Win Rate 22.90 %
Expected payoff -4.40
Gross Profit 1400.20
Gross Loss -2341.00
Total Net Profit -940.80
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.24
Total Trades 208
Won Trades 28
Lost trades 180
Win Rate 13.46 %
Expected payoff -12.36
Gross Profit 817.86
Gross Loss -3388.37
Total Net Profit -2570.51
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.86
Total Trades 192
Won Trades 48
Lost trades 144
Win Rate 25.00 %
Expected payoff -1.24
Gross Profit 1423.60
Gross Loss -1662.00
Total Net Profit -238.40
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.67
Total Trades 208
Won Trades 43
Lost trades 165
Win Rate 20.67 %
Expected payoff -2.16
Gross Profit 918.00
Gross Loss -1367.80
Total Net Profit -449.80
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.84
Total Trades 114
Won Trades 29
Lost trades 85
Win Rate 25.44 %
Expected payoff -1.32
Gross Profit 777.19
Gross Loss -927.54
Total Net Profit -150.35
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.29
Total Trades 117
Won Trades 17
Lost trades 100
Win Rate 14.53 %
Expected payoff -8.09
Gross Profit 394.20
Gross Loss -1341.00
Total Net Profit -946.80
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.78
Total Trades 124
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -2.93
Gross Profit 1298.00
Gross Loss -1661.00
Total Net Profit -363.00
-100%
-50%
0%
50%
100%

Comments