Author: emsjoflo
Profit factor:
0.62

This script is designed to automatically trade on the Forex market using the MetaTrader platform. It analyzes price trends using two technical indicators: MACD and ADX, and then it automatically buys or sells currency pairs based on specific patterns these indicators create.

Here's a simplified breakdown:

  1. Initialization: When the script starts, it sets up some initial parameters defined by the user such as risk tolerance and the amount of funds to allocate per trade.

  2. Data Collection: The script constantly monitors the market, specifically gathering information from two key indicators:

    • MACD (Moving Average Convergence Divergence): This indicator helps identify potential buy or sell signals based on the relationship between two moving averages of the price. It essentially highlights when momentum is shifting in the market.
    • ADX (Average Directional Index): This indicator measures the strength of a trend, telling the script if the market is trending strongly enough to warrant a trade. It also uses PlusDI and MinusDI to know the direction of the trend (up or down).
  3. Decision Making (Trading Logic): The core of the script lies in its decision-making process. It checks the values of MACD, ADX, PlusDI, and MinusDI against pre-defined levels and looks for specific combinations.

    • Buy Condition: The script will initiate a buy order (betting the price will go up) if:
      • The ADX is strong and strengthening.
      • The PlusDI is above MinusDI which mean price are trending upward
      • The MACD indicator suggests a buying opportunity.
    • Sell Condition: Conversely, the script will initiate a sell order (betting the price will go down) if:
      • The ADX is strong and strengthening.
      • The PlusDI is below MinusDI which mean price are trending downward
      • The MACD indicator suggests a selling opportunity.
  4. Order Management: Before entering any trades, the script checks if there are already open positions. It check the actual value of the MACD indicator to take decision to close or hold the order. If there is an open BUY order and the indicator MACD signals an downtrend it will close the BUY order. The same logic applies for SELL orders. After entering a trade, the script automatically sets a "Stop Loss" to limit potential losses.

  5. Time Delay: To avoid over-trading, the script includes a time delay that prevents it from executing new trades too frequently.

In essence, this script is an automated system that aims to identify and capitalize on trending market conditions based on the signals generated by the MACD and ADX indicators. It's important to understand that, like any automated trading system, it carries risk, and its performance depends heavily on the chosen parameters and market conditions.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
MACD HistogramMovement directional index
11 Views
0 Downloads
0 Favorites
macd_adx
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                     macd_adx.mq4 |
//|                                                     emsjoflo     |
//+------------------------------------------------------------------+
#property copyright "emsjoflo"
//If you make money with this expert, please let me know emsjoflo@yaho.com
// I also accept donations ;)
//It is only a bare-bones expert with no safeties.  Let me know if you want me to modify it for your purposes.



//---- input parameters
extern int       DMILevels=25;
extern int       ADXLevel=15; 
extern double    lots=0.1;
extern int       StopLoss=60 ;
extern int       Slippage=4;
//I'm not sure where the best place to define variables is...so I put them here and it works
double   macd,macdsig,ADX,PlusDI,MinusDI,ADXpast,PlusDIpast,MinusDIpast,SL;
int      i, buys, sells;
datetime lasttradetime;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
//get moving average info
macd=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
macdsig=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
ADX=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,1);
PlusDI=iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,1);
MinusDI=iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,1);
ADXpast=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,2);
PlusDIpast=iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,2);
MinusDIpast=iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,2);


//check for open orders first 
if (OrdersTotal()>0)
   {
   buys=0;
   sells=0;
   for (i=0;i<OrdersTotal();i++)
      {
      OrderSelect(i,SELECT_BY_POS);
      if (OrderSymbol()==Symbol())
         {
         if (OrderType()== OP_BUY)
            {
            if (macd > 0 && macdsig > 0 && macd < macdsig) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Orange);
            else buys++;
            }
         if (OrderType()== OP_SELL) 
            {
            if (macd < 0 && macdsig < 0 && macd > macdsig) OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Lime);
            else sells++;
            }
         }
      }
   }
if (ADX > ADXpast && ADX> ADXLevel && PlusDI > MinusDI && PlusDI > PlusDIpast && PlusDI > DMILevels && macd < 0 && macdsig < 0 && macd > macdsig && buys == 0 && (CurTime()-lasttradetime)/60 > Period())
   {
   //Print("Buy condition");
   if (StopLoss >1) SL=Ask-StopLoss*Point;
   OrderSend(Symbol(),OP_BUY,lots,Ask,Slippage,SL,0,"macd_adx",123,0,Lime);
   lasttradetime=CurTime();
   
   }
if (ADX > ADXpast && ADX> ADXLevel && PlusDI < MinusDI && MinusDI > MinusDIpast && MinusDI > DMILevels && macd > 0 && macdsig > 0 && macd < macdsig && sells ==0 && (CurTime()-lasttradetime)/60 > Period())
   {
   //Print ("Sell condition");
   if (StopLoss>1) SL=Bid+StopLoss*Point;
   OrderSend(Symbol(),OP_SELL,lots,Bid,Slippage,SL,0,"macd_adx",123,0,Red);
   }   
   
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+





















Profitability Reports

USD/JPY Jul 2025 - Sep 2025
0.16
Total Trades 21
Won Trades 1
Lost trades 20
Win Rate 4.76 %
Expected payoff -3.28
Gross Profit 12.72
Gross Loss -81.54
Total Net Profit -68.82
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.17
Total Trades 11
Won Trades 1
Lost trades 10
Win Rate 9.09 %
Expected payoff -3.29
Gross Profit 7.47
Gross Loss -43.62
Total Net Profit -36.15
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.37
Total Trades 15
Won Trades 1
Lost trades 14
Win Rate 6.67 %
Expected payoff -3.51
Gross Profit 31.30
Gross Loss -84.00
Total Net Profit -52.70
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.27
Total Trades 16
Won Trades 2
Lost trades 14
Win Rate 12.50 %
Expected payoff 1.36
Gross Profit 103.50
Gross Loss -81.70
Total Net Profit 21.80
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.34
Total Trades 13
Won Trades 1
Lost trades 12
Win Rate 7.69 %
Expected payoff -2.66
Gross Profit 17.50
Gross Loss -52.08
Total Net Profit -34.58
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.00
Total Trades 14
Won Trades 0
Lost trades 14
Win Rate 0.00 %
Expected payoff -3.95
Gross Profit 0.00
Gross Loss -55.29
Total Net Profit -55.29
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.42
Total Trades 17
Won Trades 1
Lost trades 16
Win Rate 5.88 %
Expected payoff -3.28
Gross Profit 40.20
Gross Loss -96.00
Total Net Profit -55.80
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.09
Total Trades 16
Won Trades 4
Lost trades 12
Win Rate 25.00 %
Expected payoff 0.42
Gross Profit 78.80
Gross Loss -72.00
Total Net Profit 6.80
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.20
Total Trades 33
Won Trades 2
Lost trades 31
Win Rate 6.06 %
Expected payoff -3.00
Gross Profit 25.42
Gross Loss -124.44
Total Net Profit -99.02
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.55
Total Trades 37
Won Trades 3
Lost trades 34
Win Rate 8.11 %
Expected payoff -2.83
Gross Profit 127.46
Gross Loss -232.07
Total Net Profit -104.61
-100%
-50%
0%
50%
100%

Comments