MA_cross_Method_PriceMode

Profit factor:
10.53

This automated trading script is designed to manage and execute trades based on a technical analysis strategy known as a Moving Average Crossover. Below is a professional breakdown of the logic used by this tool.

Core Strategy Overview

The script monitors two different Moving Averages (MAs) simultaneously. Moving averages are indicators used to smooth out price data to identify the overall direction of the market trend. By using two different periods (for example, a "fast" moving average and a "slow" moving average), the script can identify specific moments when the momentum of the market shifts.

How the Logic Works

1. Signal Detection (The Crossover) The system constantly calculates the current values of two Moving Averages. It looks for specific "crossovers" to determine when to enter or exit a trade:

  • Buy Signal: Triggered when the faster moving average crosses from below to above the slower moving average. This typically suggests that upward momentum is increasing.
  • Sell Signal: Triggered when the faster moving average crosses from above to below the slower moving average. This typically suggests that downward momentum is taking over.

2. Trade Execution Rules To ensure organized trading and prevent over-exposure, the script follows strict operational rules:

  • New Bar Verification: The script is designed to check for signals only at the start of a new price candle (a "New Bar"). This prevents the system from opening multiple trades or reacting prematurely to minor price fluctuations within a single candle.
  • Position Management: The logic includes a check to ensure that it does not open redundant positions. For instance, if a Buy position is already active, it will not open another one.
  • Automatic Closures: The script actively monitors existing trades. If the market trend reverses (i.e., a "Sell" crossover occurs while a "Buy" trade is still open), the script will automatically close the current position to protect capital and prepare for the new direction.

3. Customizable Parameters The logic is built to be flexible, allowing users to define several key components without needing to alter the underlying code:

  • Moving Average Type: You can choose between different calculation methods (such as Simple, Exponential, Smoothed, or Linear Weighted).
  • Price Source: You can decide which price data the moving averages should base their calculations on (e.g., Close price, Open price, High/Low, or Median prices).
  • Time Offsets and Periods: Users can define how far back the averages look and apply "shifts" to adjust the timing of the signals.

Summary of Behavior

In short, this script acts as an automated trend-follower. It waits for a specific mathematical confirmation that the market trend has shifted, enters a trade in the direction of that shift at the start of a new candle, and automatically exits the trade if the indicators suggest the trend has reversed.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
10 Views
0 Downloads
0 Favorites
MA_cross_Method_PriceMode
//============================================================================================
//
//
//
//
//
//============================================================================================
extern int    MA1_Period=3;                              // Ïåðèîä 1-é ÌÀ
extern int    MA2_Period=13;                             // Ïåðèîä 2-é ÌÀ
extern int    MA1_Method=0;                              // Ìåòîä âû÷èñëåíèÿ ÌÀ1 (SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int    MA2_Method=3;                              // Ìåòîä âû÷èñëåíèÿ ÌÀ2 (SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int    MA1_Price=0;                               // Ìåòîä âû÷èñëåíèÿ öåíû ÌÀ1 
extern int    MA2_Price=4;                               // Ìåòîä âû÷èñëåíèÿ öåíû ÌÀ2
extern int    MA1_Shift=0;                               // Âðåìåííîé ñäâèã ÌÀ1
extern int    MA2_Shift=0;                               // Âðåìåííîé ñäâèã ÌÀ2
extern double Lot = 0.1;                                 // Ôèêñèðîâàííûé ëîò
extern int    slippage = 0;                              // Îòêëîíåíèå öåíû äëÿ ðûíî÷íûõ îðäåðîâ 
int New_Bar;                                             // 0/1 Ôàêò îáðàçîâàíèÿ íîâîãî áàðà
int Time_0;                                              // Âðåìÿ íà÷àëà íîâîãî áàðà
int PosOpen;                                             // Íàïðàâëåíèå ïåðåñå÷åíèÿ
int PosClose;                                            // Íàïðàâëåíèå ïåðåñå÷åíèÿ
int total;                                               // Êîëè÷åñòâî îòêðûòûõ îðäåðîâ
double MA1_0;                                            // Òåêóùåå çíà÷åíèå 1-é ÌÀ (ðîçîâ)
double MA1_1;                                            // Ïðåäûäóùåå çíà÷åíèå 1-é ÌÀ (ðîçîâ)
double MA2_0;                                            // Òåêóùåå çíà÷åíèå 2-é ÌÀ (ãîëóáàÿ)
double MA2_1;                                            // Ïðåäûäóùåå çíà÷åíèå 2-é ÌÀ (ãîëóáàÿ)
int orderBuy;                                            // 1 = ôàêò íàëèèÿ îðäåðà Buy
int orderSell;                                           // 1 = ôàêò íàëèèÿ îðäåðà Sell 
//============================================================================================
int init()  
   {

   }  
//============================================================================================
int start()  
   {
   orderBuy=0;
   orderSell=0; 
   double price;  
   int openOrders=0;
   int total=OrdersTotal();                                  // Îáùåå êîëè÷åñòâî îðäåðîâ
   for(int i=total-1;i>=0;i--)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)     // Âûáèðàåì îðäåð
         {
         if(OrderType()==OP_BUY)                             // Åñëè ñòîèò îðäåð íà ïîêóïêó
            {
            orderBuy=1;
            if(CrossPositionClose()==1)                      // Çàêðûâåì îðäåð, åñëè óäîâëåòâîðÿåò
               {                                             // óñëîâèþ CrossPositionClose()=1
               price=MarketInfo(Symbol(),MODE_BID);
               OrderClose(OrderTicket(),OrderLots(),price,slippage,CLR_NONE);
               }
            }
         if(OrderType()==OP_SELL)                            // Åñëè ñòîèò îðäåð íà ïîêóïêó
            {
            orderSell=1;
            if(CrossPositionClose()==2)                      // Çàêðûâåì îðäåð, åñëè óäîâëåòâîðÿåò
               {                                             // óñëîâèþ CrossPositionClose()=2
               price=MarketInfo(Symbol(),MODE_ASK);
               OrderClose(OrderTicket(),OrderLots(),price,slippage,CLR_NONE);
               }
            }
         }
      }
   
   New_Bar=0;                                                // Äëÿ íà÷àëà îáíóëèìñÿ
   if (Time_0 != Time[0])                                    // Åñëè óæå äðóãîå âðåìÿ íà÷àëà áàðà
      {
      New_Bar= 1;                                            // À âîò è íîâûé áàð
      Time_0 = Time[0];                                      // Çàïîìíèì âðåìÿ íà÷àëà íîâîãî áàðà
      } 
   
   MA1_0=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 0);    // Òåêóùåå    çíà÷åíèå 1-é ÌÀ
   MA1_1=iMA(NULL,0, MA1_Period, MA1_Shift,MAMethod(MA1_Method), MAPrice(MA1_Price), 1);    // Ïðåäûäóùåå çíà÷åíèå 1-é ÌÀ
   MA2_0=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 0);    // Òåêóùåå    çíà÷åíèå 2-é ÌÀ
   MA2_1=iMA(NULL,0, MA2_Period, MA2_Shift,MAMethod(MA2_Method), MAPrice(MA2_Price), 1);    // Ïðåäûäóùåå çíà÷åíèå 2-é ÌÀ
   
   if (CrossPositionOpen()==1 && New_Bar==1)                 // Äâèæåíèå ñíèçó ââåðõ = îòêð. Buy
      {
      OpenBuy();
      }      
   if (CrossPositionOpen()==2 && New_Bar==1)                 // Äâèæåíèå ñâåðõó âíèç = îòêð. Sell
      {
      OpenSell();
      }    
   return;
   }  
//============================================================================================
int CrossPositionOpen()
   {
   PosOpen=0;                                                 // Âîò ãäå ñîáàêà çàðûòà!!:)
   if ((MA1_1<=MA2_0 && MA1_0>MA2_0) || (MA1_1<MA2_0 && MA1_0>=MA2_0))   // Ïåðåñå÷åíèå ñíèçó ââåðõ  
      {
      PosOpen=1;
      }                  
   if ((MA1_1>=MA2_0 && MA1_0<MA2_0) || (MA1_1>MA2_0 && MA1_0<=MA2_0))   // Ïåðåñå÷åíèå ñâåðõó âíèç
      {
      PosOpen=2;
      }             
   return(PosOpen);                                          // Âîçâðàùàåì íàïðàâëåíèå ïåðåñå÷åí.
   }
//============================================================================================
int CrossPositionClose()
   {
   PosClose=0;                                                // Âîò ãäå ñîáàêà çàðûòà!!:)
   if ((MA1_1>=MA2_0 && MA1_0<MA2_0) || (MA1_1>MA2_0 && MA1_0<=MA2_0))   // Ïåðåñå÷åíèå ñâåðõó âíèç        {
      {
      PosClose=1;
      }                  
   if ((MA1_1<=MA2_0 && MA1_0>MA2_0) || (MA1_1<MA2_0 && MA1_0>=MA2_0))   // Ïåðåñå÷åíèå ñíèçó ââåðõ
      {
      PosClose=2;
      }             
   return(PosClose);                                          // Âîçâðàùàåì íàïðàâëåíèå ïåðåñå÷åí.
   }
//============================================================================================
int OpenBuy() 
   {
   if (total==1)
      {
      OrderSelect(0, SELECT_BY_POS,MODE_TRADES);              // Âûäåëèì îðäåð
      if (OrderType()==OP_BUY) return;                        // Åñëè îí buy, òî íå îòêðûâàåìñÿ
      }
   OrderSend(Symbol(),OP_BUY, Lot, Ask, slippage, 0, 0, "Buy: MA_cross_Method_PriceMode", 1, 0, CLR_NONE);// Îòêðûâàåìñÿ
   return;
   }
//============================================================================================
int OpenSell() 
   {
   if (total==1)
      {
      OrderSelect(0, SELECT_BY_POS,MODE_TRADES);              // Âûäåëèì îðäåð
      if (OrderType()==OP_SELL) return;                       // Åñëè îí sell, òî íå îòêðûâàåìñÿ
      }
   OrderSend(Symbol(),OP_SELL, Lot, Bid, slippage, 0, 0, "Sell: MA_cross_Method_PriceMode", 2, 0, CLR_NONE);
   return;
   }
//============================================================================================
int MAMethod(int MA_Method)
   {
      switch(MA_Method)
        {
         case 0: return(0);                                   // Âîçâðàùàåò MODE_SMA=0
         case 1: return(1);                                   // Âîçâðàùàåò MODE_EMA=1
         case 2: return(2);                                   // Âîçâðàùàåò MODE_SMMA=2
         case 3: return(3);                                   // Âîçâðàùàåò MODE_LWMA=3
        }
   }
//============================================================================================
int MAPrice(int MA_Price)
   {
      switch(MA_Price)
        {
         case 0: return(PRICE_CLOSE);                         // Âîçâðàùàåò PRICE_CLOSE=0        
         case 1: return(PRICE_OPEN);                          // Âîçâðàùàåò PRICE_OPEN=1
         case 2: return(PRICE_HIGH);                          // Âîçâðàùàåò PRICE_HIGH=2
         case 3: return(PRICE_LOW);                           // Âîçâðàùàåò PRICE_LOW=3
         case 4: return(PRICE_MEDIAN);                        // Âîçâðàùàåò PRICE_MEDIAN=4
         case 5: return(PRICE_TYPICAL);                       // Âîçâðàùàåò PRICE_TYPICAL=5
         case 6: return(PRICE_WEIGHTED);                      // Âîçâðàùàåò PRICE_WEIGHTED=6
        }
   }
//============================================================================================

Profitability Reports

EUR/USD Jul 2025 - Sep 2025
160.65
Total Trades 321
Won Trades 75
Lost trades 246
Win Rate 23.36 %
Expected payoff 983.17
Gross Profit 317574.10
Gross Loss -1976.80
Total Net Profit 315597.30
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.91
Total Trades 379
Won Trades 89
Lost trades 290
Win Rate 23.48 %
Expected payoff -0.54
Gross Profit 1948.18
Gross Loss -2151.99
Total Net Profit -203.81
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.68
Total Trades 183
Won Trades 42
Lost trades 141
Win Rate 22.95 %
Expected payoff -2.10
Gross Profit 816.79
Gross Loss -1200.75
Total Net Profit -383.96
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.66
Total Trades 351
Won Trades 90
Lost trades 261
Win Rate 25.64 %
Expected payoff -2.37
Gross Profit 1600.90
Gross Loss -2434.40
Total Net Profit -833.50
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.63
Total Trades 601
Won Trades 147
Lost trades 454
Win Rate 24.46 %
Expected payoff -1.87
Gross Profit 1948.10
Gross Loss -3071.00
Total Net Profit -1122.90
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.58
Total Trades 634
Won Trades 137
Lost trades 497
Win Rate 21.61 %
Expected payoff -2.00
Gross Profit 1758.50
Gross Loss -3028.50
Total Net Profit -1270.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.57
Total Trades 175
Won Trades 45
Lost trades 130
Win Rate 25.71 %
Expected payoff -4.09
Gross Profit 938.30
Gross Loss -1654.70
Total Net Profit -716.40
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
0.53
Total Trades 628
Won Trades 131
Lost trades 497
Win Rate 20.86 %
Expected payoff -4.12
Gross Profit 2944.95
Gross Loss -5530.12
Total Net Profit -2585.17
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.51
Total Trades 344
Won Trades 75
Lost trades 269
Win Rate 21.80 %
Expected payoff -4.03
Gross Profit 1431.06
Gross Loss -2817.60
Total Net Profit -1386.54
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.50
Total Trades 388
Won Trades 73
Lost trades 315
Win Rate 18.81 %
Expected payoff -2.19
Gross Profit 856.20
Gross Loss -1704.40
Total Net Profit -848.20
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.50
Total Trades 357
Won Trades 82
Lost trades 275
Win Rate 22.97 %
Expected payoff -3.35
Gross Profit 1215.39
Gross Loss -2413.01
Total Net Profit -1197.62
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.46
Total Trades 352
Won Trades 62
Lost trades 290
Win Rate 17.61 %
Expected payoff -2.73
Gross Profit 814.80
Gross Loss -1776.50
Total Net Profit -961.70
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.43
Total Trades 204
Won Trades 44
Lost trades 160
Win Rate 21.57 %
Expected payoff -4.52
Gross Profit 689.90
Gross Loss -1611.40
Total Net Profit -921.50
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2025 - Feb 2026
0.39
Total Trades 564
Won Trades 112
Lost trades 452
Win Rate 19.86 %
Expected payoff -5.14
Gross Profit 1848.80
Gross Loss -4748.22
Total Net Profit -2899.42
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.34
Total Trades 208
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -6.41
Gross Profit 688.80
Gross Loss -2021.40
Total Net Profit -1332.60
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.18
Total Trades 351
Won Trades 39
Lost trades 312
Win Rate 11.11 %
Expected payoff -10.73
Gross Profit 845.14
Gross Loss -4611.81
Total Net Profit -3766.67
-100%
-50%
0%
50%
100%

Comments