Author: emsjoflo
Profit factor:
0.76

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
8 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 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%
USD/CAD Jan 2025 - Jul 2025
0.97
Total Trades 32
Won Trades 6
Lost trades 26
Win Rate 18.75 %
Expected payoff -0.11
Gross Profit 107.44
Gross Loss -111.03
Total Net Profit -3.59
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
1.30
Total Trades 36
Won Trades 5
Lost trades 31
Win Rate 13.89 %
Expected payoff 1.55
Gross Profit 241.70
Gross Loss -186.00
Total Net Profit 55.70
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.01
Total Trades 39
Won Trades 1
Lost trades 38
Win Rate 2.56 %
Expected payoff -5.80
Gross Profit 1.80
Gross Loss -228.00
Total Net Profit -226.20
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.77
Total Trades 22
Won Trades 2
Lost trades 20
Win Rate 9.09 %
Expected payoff -0.92
Gross Profit 66.50
Gross Loss -86.71
Total Net Profit -20.21
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.95
Total Trades 22
Won Trades 1
Lost trades 21
Win Rate 4.55 %
Expected payoff -0.20
Gross Profit 78.11
Gross Loss -82.54
Total Net Profit -4.43
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.77
Total Trades 46
Won Trades 5
Lost trades 41
Win Rate 10.87 %
Expected payoff -1.24
Gross Profit 189.00
Gross Loss -246.00
Total Net Profit -57.00
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.59
Total Trades 34
Won Trades 5
Lost trades 29
Win Rate 14.71 %
Expected payoff -2.09
Gross Profit 102.80
Gross Loss -174.00
Total Net Profit -71.20
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.00
Total Trades 14
Won Trades 0
Lost trades 14
Win Rate 0.00 %
Expected payoff -4.25
Gross Profit 0.00
Gross Loss -59.52
Total Net Profit -59.52
-100%
-50%
0%
50%
100%

Comments