Author: Expert Advisor Builder
Profit factor:
2.85

This automated trading script is designed to manage and execute trades based on moving average trends. It uses a systematic approach to identify market momentum and automatically handles trade entries, exits, and risk management.

Core Trading Logic

The script functions by monitoring two different Moving Average (MA) indicators on a 5-minute chart. By comparing a fast-moving average against a slower-moving average, the system determines the current direction of the market:

  • Buy Signals: When the fast moving average crosses above the slow moving average, the system identifies an upward trend and prepares to enter a "Long" position.
  • Sell Signals: When the fast moving average falls below the slow moving average, the system identifies a downward trend and prepares to enter a "Short" position.

Entry Mechanism

Unlike scripts that enter a trade immediately upon a signal, this tool utilizes Pending Orders. Once a trend is identified:

  • It places a Buy Stop order at a specific distance (defined by pips) above the current price for upward trends.
  • It places a Sell Stop order at a specific distance below the current price for downward trends. This ensures that a trade is only triggered if the price continues to move in the intended direction, providing an extra layer of confirmation.

Trade Management and Protection

The script includes several automated features to manage active trades:

  • Position Tracking: It constantly monitors your open positions and pending orders to ensure it doesn't over-leverage by opening unnecessary duplicate trades.
  • Stop Loss & Take Profit: Every trade is automatically assigned a safety net (Stop Loss) to limit potential losses and a target (Take Profit) to secure gains.
  • Trailing Stop: This dynamic feature adjusts the Stop Loss of an active trade as the price moves in your favor. If the market moves significantly past your entry point, the script "trails" the stop loss behind the current price, locking in profits while allowing the trade room to continue running.

Execution Modes

The logic is flexible regarding how it processes data:

  1. Tick Mode: The script can be set to scan for changes every single time the market price moves (tick by tick).
  2. Bar Mode: Alternatively, it can be configured to check for new signals only when a new candle (bar) forms on the chart.
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
12 Views
0 Downloads
0 Favorites
jfk
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//|                Please do not remove this header.                 |
//+------------------------------------------------------------------+
#property copyright "Expert Advisor Builder"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;
extern bool EachTickMode = True;
extern double Lots = 0.1;
extern int Slippage = 3;
extern bool StopLossMode = True;
extern int StopLoss = 30;
extern bool TakeProfitMode = True;
extern int TakeProfit = 100;
extern bool TrailingStopMode = True;
extern int TrailingStop = 30;
extern int PipsForEntry = 10;
extern bool Short = True;
extern bool Long = True;


#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

int BarCount;
int Current;
int b,s;

bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;
   if (EachTickMode) Current = 0; else Current = 1;
   return(0);  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() { return(0);}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   PosCounter();
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel, Opentrades, PosCounter;

   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+

   double Buy1_1 = iMA(NULL, PERIOD_M5, 10, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
   double Buy1_2 = iMA(NULL, PERIOD_M5, 25, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
   double Sell1_1 = iMA(NULL, PERIOD_M5, 10, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
   double Sell1_2 = iMA(NULL, PERIOD_M5, 25, 0, MODE_SMA, PRICE_CLOSE, Current + 0);

   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
  
   for (int i = 0; i < Total; i ++) {
      OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+


            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (!EachTickMode) BarCount = Bars;
               break;
            }
            //Trailing stop
            if(TrailingStopMode && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     break;
                  }
               }
            }
         } else {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+


            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (!EachTickMode) BarCount = Bars;
               break;
            }
            //Trailing stop
            if(TrailingStopMode && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     break;
                  }
            }
            }
         }
      }
   }
     //used this code from another EA but changed it to suit me
   if(Buy1_1 > Buy1_2 && b==0 && Long==True) {
      OrderSend(Symbol(), OP_BUYSTOP, Lots, Ask+PipsForEntry*Point, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
      return(0);  }
        
   if(Sell1_1 < Sell1_2 && s==0 && Short==True)   {
      OrderSend(Symbol(), OP_SELLSTOP, Lots, Bid-PipsForEntry*Point, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
      return(0);  }

   //END OF MAIN SECTION
return(0);}
     
//+------------------------------------------------------------------+

void PosCounter() {
   b=0;s=0;
   for(int cnt=0;cnt<=OrdersTotal();cnt++)   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()) {
         if(OrderType() == OP_SELL)       s++;
         if(OrderType() == OP_SELLSTOP)   s++;
         if(OrderType() == OP_BUY)        b++;
         if(OrderType() == OP_BUYSTOP)    b++;}}}

Profitability Reports

PERFORMANCE BY SYMBOL

Expected payoff

Average expected payoff across the available backtests for each symbol.

Positive Negative
32 reports
USD/JPY Jan 2025 - Jul 2025
73.65
Total Trades 422
Won Trades 407
Lost trades 15
Win Rate 96.45 %
Expected payoff 1.30
Gross Profit 557.54
Gross Loss -7.57
Total Net Profit 549.97
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
4.57
Total Trades 277
Won Trades 197
Lost trades 80
Win Rate 71.12 %
Expected payoff 1.23
Gross Profit 435.60
Gross Loss -95.40
Total Net Profit 340.20
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2025 - Feb 2026
4.08
Total Trades 127
Won Trades 95
Lost trades 32
Win Rate 74.80 %
Expected payoff 1.25
Gross Profit 210.91
Gross Loss -51.64
Total Net Profit 159.27
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
1.83
Total Trades 839
Won Trades 660
Lost trades 179
Win Rate 78.67 %
Expected payoff 53.70
Gross Profit 99155.83
Gross Loss -54097.42
Total Net Profit 45058.41
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
1.63
Total Trades 990
Won Trades 785
Lost trades 205
Win Rate 79.29 %
Expected payoff 37.58
Gross Profit 96197.38
Gross Loss -58990.97
Total Net Profit 37206.41
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
1.40
Total Trades 392
Won Trades 231
Lost trades 161
Win Rate 58.93 %
Expected payoff 100.79
Gross Profit 137237.77
Gross Loss -97727.51
Total Net Profit 39510.26
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.15
Total Trades 401
Won Trades 175
Lost trades 226
Win Rate 43.64 %
Expected payoff 0.04
Gross Profit 129.23
Gross Loss -112.65
Total Net Profit 16.58
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.96
Total Trades 501
Won Trades 229
Lost trades 272
Win Rate 45.71 %
Expected payoff -0.03
Gross Profit 365.80
Gross Loss -382.10
Total Net Profit -16.30
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.48
Total Trades 455
Won Trades 200
Lost trades 255
Win Rate 43.96 %
Expected payoff -3.84
Gross Profit 1622.90
Gross Loss -3370.60
Total Net Profit -1747.70
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.42
Total Trades 454
Won Trades 198
Lost trades 256
Win Rate 43.61 %
Expected payoff -3.78
Gross Profit 1235.50
Gross Loss -2950.80
Total Net Profit -1715.30
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.28
Total Trades 258
Won Trades 61
Lost trades 197
Win Rate 23.64 %
Expected payoff -1.87
Gross Profit 185.40
Gross Loss -667.37
Total Net Profit -481.97
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.24
Total Trades 500
Won Trades 119
Lost trades 381
Win Rate 23.80 %
Expected payoff -4.80
Gross Profit 743.00
Gross Loss -3141.10
Total Net Profit -2398.10
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.13
Total Trades 335
Won Trades 43
Lost trades 292
Win Rate 12.84 %
Expected payoff -1.58
Gross Profit 77.40
Gross Loss -606.60
Total Net Profit -529.20
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.09
Total Trades 390
Won Trades 76
Lost trades 314
Win Rate 19.49 %
Expected payoff -0.69
Gross Profit 26.57
Gross Loss -294.37
Total Net Profit -267.80
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.05
Total Trades 262
Won Trades 21
Lost trades 241
Win Rate 8.02 %
Expected payoff -1.28
Gross Profit 18.77
Gross Loss -353.57
Total Net Profit -334.80
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.04
Total Trades 323
Won Trades 30
Lost trades 293
Win Rate 9.29 %
Expected payoff -2.63
Gross Profit 38.30
Gross Loss -889.40
Total Net Profit -851.10
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.04
Total Trades 500
Won Trades 112
Lost trades 388
Win Rate 22.40 %
Expected payoff -3.01
Gross Profit 64.60
Gross Loss -1571.40
Total Net Profit -1506.80
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.01
Total Trades 120
Won Trades 3
Lost trades 117
Win Rate 2.50 %
Expected payoff -7.36
Gross Profit 5.60
Gross Loss -889.20
Total Net Profit -883.60
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.00
Total Trades 486
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -3.90
Gross Profit 5.30
Gross Loss -1898.50
Total Net Profit -1893.20
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00
Total Trades 280
Won Trades 9
Lost trades 271
Win Rate 3.21 %
Expected payoff -1.72
Gross Profit 0.50
Gross Loss -483.30
Total Net Profit -482.80
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.00
Total Trades 233
Won Trades 0
Lost trades 233
Win Rate 0.00 %
Expected payoff -5.42
Gross Profit 0.00
Gross Loss -1264.01
Total Net Profit -1264.01
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.00
Total Trades 225
Won Trades 0
Lost trades 225
Win Rate 0.00 %
Expected payoff -7.00
Gross Profit 0.00
Gross Loss -1575.18
Total Net Profit -1575.18
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.00
Total Trades 252
Won Trades 0
Lost trades 252
Win Rate 0.00 %
Expected payoff -2.21
Gross Profit 0.00
Gross Loss -557.00
Total Net Profit -557.00
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.00
Total Trades 423
Won Trades 0
Lost trades 423
Win Rate 0.00 %
Expected payoff -6.20
Gross Profit 0.00
Gross Loss -2622.50
Total Net Profit -2622.50
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.00
Total Trades 195
Won Trades 0
Lost trades 195
Win Rate 0.00 %
Expected payoff -1.35
Gross Profit 0.00
Gross Loss -262.80
Total Net Profit -262.80
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.00
Total Trades 242
Won Trades 0
Lost trades 242
Win Rate 0.00 %
Expected payoff -3.84
Gross Profit 0.00
Gross Loss -929.26
Total Net Profit -929.26
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.00
Total Trades 195
Won Trades 8
Lost trades 187
Win Rate 4.10 %
Expected payoff -1.38
Gross Profit 0.39
Gross Loss -269.57
Total Net Profit -269.18
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.00
Total Trades 212
Won Trades 0
Lost trades 212
Win Rate 0.00 %
Expected payoff -9.79
Gross Profit 0.00
Gross Loss -2075.33
Total Net Profit -2075.33
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.00
Total Trades 183
Won Trades 1
Lost trades 182
Win Rate 0.55 %
Expected payoff -4.93
Gross Profit 2.27
Gross Loss -904.58
Total Net Profit -902.31
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.00
Total Trades 381
Won Trades 1
Lost trades 380
Win Rate 0.26 %
Expected payoff -6.32
Gross Profit 0.10
Gross Loss -2409.50
Total Net Profit -2409.40
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.00
Total Trades 295
Won Trades 0
Lost trades 295
Win Rate 0.00 %
Expected payoff -1.49
Gross Profit 0.00
Gross Loss -439.80
Total Net Profit -439.80
-100%
-50%
0%
50%
100%
GBP/AUD Oct 2025 - Feb 2026
0.00
Total Trades 172
Won Trades 0
Lost trades 172
Win Rate 0.00 %
Expected payoff -21.05
Gross Profit 0.00
Gross Loss -3620.31
Total Net Profit -3620.31
-100%
-50%
0%
50%
100%

Comments