MACD Sample russian

Profit factor:
0.82
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
MACD HistogramMoving average indicator
4 Views
0 Downloads
0 Favorites
MACD Sample russian
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;
double Points;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init ()
  {
   Points = MarketInfo (Symbol(), MODE_POINT);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double MacdCurrent=0, MacdPrevious=0, SignalCurrent=0;
   double SignalPrevious=0, MaCurrent=0, MaPrevious=0;
   int cnt=0, total;
// ïåðâè÷íûå ïðîâåðêè äàííûõ
// âàæíî óäîñòîâåðèòüñÿ ÷òî ýêñïåðò ðàáîòàåò íà íîðìàëüíîì ãðàôèêå è
// ïîëüçîâàòåëü ïðàâèëüíî âûñòàâèë âíåøíèå ïåðåìåííûå (Lots, StopLoss,
// TakeProfit, TrailingStop)
// â íàøåì ñëó÷àå ïðîâåðÿåì òîëüêî TakeProfit
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  // íà ãðàôèêå ìåíåå 100 áàðîâ
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // ïðîâåðÿåì TakeProfit
     }
// ðàäè óïðîùåíèÿ è óñêîðåíèÿ êîäà, ñîõðàíèì íåîáõîäèìûå
// äàííûå èíäèêàòîðîâ âî âðåìåííûõ ïåðåìåííûõ
   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   MaCurrent=iMA(NULL,0,MATrendPeriod,MODE_EMA,0,PRICE_CLOSE,0);
   MaPrevious=iMA(NULL,0,MATrendPeriod,MODE_EMA,0,PRICE_CLOSE,1);
// òåïåðü íàäî îïðåäåëèòüñÿ - â êàêîì ñîñòîÿíèè òîðãîâûé òåðìèíàë?
// ïðîâåðèì, åñòü ëè ðàíåå îòêðûòûå ïîçèöèè èëè îðäåðû?
   if(OrdersTotal()<1) 
     {
      // íåò íè îäíîãî îòêðûòîãî îðäåðà
      // íà âñÿêèé ñëó÷àé ïðîâåðèì, åñëè ó íàñ ñâîáîäíûå äåíüãè íà ñ÷åòó?
      // çíà÷åíèå 1000 âçÿòî äëÿ ïðèìåðà, îáû÷íî ìîæíî îòêðûòü 1 ëîò
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money");
         return(0);  // äåíåã íåò - âûõîäèì
        }
      // ïðîâåðèì, íå ñëèøêîì ëè ÷àñòî ïûòàåìñÿ îòêðûòüñÿ?
      // åñëè ïîñëåäíèé ðàç òîðãîâàëè ìåíåå ÷åì 5 ìèíóò(5*60=300 ñåê)
      // íàçàä, òî âûõîäèì
      // If((CurTime-LastTradeTime)<300) { Exit }
      // ïðîâåðÿåì íà âîçìîæíîñòü âñòàòü â äëèííóþ ïîçèöèþ (BUY)
      if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs(MacdCurrent)>(MACDOpenLevel*Points) && MaCurrent>MaPrevious)
        {
         OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Points,"macd sample",16384,0,Red); // èñïîëíÿåì
         if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
         return(0); // âûõîäèì, òàê êàê âñå ðàâíî ïîñëå ñîâåðøåíèÿ òîðãîâîé îïåðàöèè
            // íàñòóïèë 10-òè ñåêóíäíûé òàéìàóò íà ñîâåðøåíèå òîðãîâûõ îïåðàöèé
        }
      // ïðîâåðÿåì íà âîçìîæíîñòü âñòàòü â êîðîòêóþ ïîçèöèþ (SELL)
      if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
         MacdCurrent>(MACDOpenLevel*Points) && MaCurrent<MaPrevious)
        {
         OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Points,"macd sample",16384,0,Red); // èñïîëíÿåì
         if(GetLastError()==0)Print("Order opened : ",OrderOpenPrice());
         return(0); // âûõîäèì
        };
      // çäåñü ìû çàâåðøèëè ïðîâåðêó íà âîçìîæíîñòü îòêðûòèÿ íîâûõ ïîçèöèé.
      // íîâûå ïîçèöèè îòêðûòû íå áûëè è ïðîñòî âûõîäèì ïî Exit, òàê êàê
      // âñå ðàâíî àíàëèçèðîâàòü íå÷åãî
      return(0);
     };
   // ïåðåõîäèì ê âàæíîé ÷àñòè ýêñïåðòà - êîíòðîëþ îòêðûòûõ ïîçèöèé
   // 'âàæíî ïðàâèëüíî âîéòè â ðûíîê, íî âûéòè - åùå âàæíåå...'
   total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL && // ýòî îòêðûòàÿ ïîçèöèÿ? OP_BUY èëè OP_SELL 
         OrderSymbol()==Symbol())    // èíñòðóìåíò ñîâïàäàåò?
        {
         if(OrderType()==OP_BUY)   // îòêðûòà äëèííàÿ ïîçèöèÿ
           {
            // ïðîâåðèì, ìîæåò óæå ïîðà çàêðûâàòüñÿ?
            if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
               MacdCurrent>(MACDCloseLevel*Points))
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // çàêðûâàåì ïîçèöèþ
                 return(0); // âûõîäèì
                };
            // ïðîâåðèì - ìîæåò ìîæíî/íóæíî óæå òðåéëèíã ñòîï ñòàâèòü?
            if(TrailingStop>0)  // ïîëüçîâàòåëü âûñòàâèë â íàñòðîéêàõ òðåéëèíãñòîï
              {                 // çíà÷èò ìû èäåì åãî ïðîâåðÿòü
               if(Bid-OrderOpenPrice()>Points*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Points*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Points*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
         else // èíà÷å ýòî êîðîòêàÿ ïîçèöèÿ
           {
            // ïðîâåðèì, ìîæåò óæå ïîðà çàêðûâàòüñÿ?
            if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
               MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*Points))
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // çàêðûâàåì ïîçèöèþ
               return(0); // âûõîäèì
              }
            // ïðîâåðèì - ìîæåò ìîæíî/íóæíî óæå òðåéëèíã ñòîï ñòàâèòü?
            if(TrailingStop>0)  // ïîëüçîâàòåëü âûñòàâèë â íàñòðîéêàõ òðåéëèíãñòîï
              {                 // çíà÷èò ìû èäåì åãî ïðîâåðÿòü
               if((OrderOpenPrice()-Ask)>(Points*TrailingStop))
                 {
                  if(OrderStopLoss()==0.0 || 
                     OrderStopLoss()>(Ask+Points*TrailingStop))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Points*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
// the end.

Profitability Reports

GBP/USD Jul 2025 - Sep 2025
0.11
Total Trades 6
Won Trades 4
Lost trades 2
Win Rate 66.67 %
Expected payoff -21.10
Gross Profit 15.50
Gross Loss -142.10
Total Net Profit -126.60
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.39
Total Trades 7
Won Trades 6
Lost trades 1
Win Rate 85.71 %
Expected payoff -2.64
Gross Profit 12.01
Gross Loss -30.52
Total Net Profit -18.51
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.64
Total Trades 30
Won Trades 28
Lost trades 2
Win Rate 93.33 %
Expected payoff -1.51
Gross Profit 78.94
Gross Loss -124.31
Total Net Profit -45.37
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.55
Total Trades 15
Won Trades 14
Lost trades 1
Win Rate 93.33 %
Expected payoff -2.80
Gross Profit 50.60
Gross Loss -92.60
Total Net Profit -42.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.69
Total Trades 10
Won Trades 9
Lost trades 1
Win Rate 90.00 %
Expected payoff -1.23
Gross Profit 27.90
Gross Loss -40.20
Total Net Profit -12.30
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.96
Total Trades 60
Won Trades 58
Lost trades 2
Win Rate 96.67 %
Expected payoff -0.11
Gross Profit 153.88
Gross Loss -160.71
Total Net Profit -6.83
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
1.08
Total Trades 39
Won Trades 37
Lost trades 2
Win Rate 94.87 %
Expected payoff 0.27
Gross Profit 137.81
Gross Loss -127.24
Total Net Profit 10.57
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.68
Total Trades 56
Won Trades 55
Lost trades 1
Win Rate 98.21 %
Expected payoff 1.07
Gross Profit 147.11
Gross Loss -87.36
Total Net Profit 59.75
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.48
Total Trades 34
Won Trades 31
Lost trades 3
Win Rate 91.18 %
Expected payoff -2.66
Gross Profit 85.00
Gross Loss -175.50
Total Net Profit -90.50
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
1.23
Total Trades 41
Won Trades 40
Lost trades 1
Win Rate 97.56 %
Expected payoff 0.56
Gross Profit 124.40
Gross Loss -101.40
Total Net Profit 23.00
-100%
-50%
0%
50%
100%

Comments