MACD Sample russian

Profit factor:
0.79
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
5 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

USD/JPY Jul 2025 - Sep 2025
0.00
Total Trades 13
Won Trades 13
Lost trades 0
Win Rate 100.00 %
Expected payoff 2.61
Gross Profit 33.94
Gross Loss 0.00
Total Net Profit 33.94
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
3.18
Total Trades 10
Won Trades 9
Lost trades 1
Win Rate 90.00 %
Expected payoff 2.76
Gross Profit 40.25
Gross Loss -12.64
Total Net Profit 27.61
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.34
Total Trades 22
Won Trades 17
Lost trades 5
Win Rate 77.27 %
Expected payoff -3.78
Gross Profit 43.13
Gross Loss -126.35
Total Net Profit -83.22
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.16
Total Trades 6
Won Trades 5
Lost trades 1
Win Rate 83.33 %
Expected payoff -10.15
Gross Profit 11.60
Gross Loss -72.50
Total Net Profit -60.90
-100%
-50%
0%
50%
100%
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%

Comments