Author: The # one Lotfy
Profit factor:
1.31

Here's a breakdown of what the MetaTrader script does, explained in simple terms:

This script is designed to automatically trade on the Forex market using the MetaTrader platform. It analyzes market conditions using technical indicators and then places buy or sell orders based on that analysis. The goal is to profit from short-term price movements.

Here's how it works step-by-step:

  1. Initialization: When the script starts, it sets up some basic settings. These include:

    • Moving Averages: It defines parameters for calculating two moving averages, which are used to smooth out price data and identify trends.

    • Lot Size: It sets a base "lot size" for trades, which determines how much of your account balance is risked on each trade. It adjusts this lot size based on your account balance.

    • Buy/Sell Level: It defines a level that triggers when a buy or sell action occurs.

  2. Market Analysis: The script continuously monitors the market using two technical indicators:

    • Commodity Channel Index (CCI): This indicator helps identify when an asset is overbought or oversold, potentially signaling a price reversal.

    • Moving Average Convergence Divergence (MACD): The MACD indicator helps to identify trends and potential buy/sell signals.

  3. Order Management: The script keeps track of all open orders related to its specific "magic number" (343) for identification. It counts how many buy and sell orders are currently active.

  4. Trading Logic: The core of the script's decision-making process:

    • Buy Condition: If both the CCI and MACD indicators suggest the market is oversold (below a certain level), and there are no open buy orders, the script places a buy order. It calculates the size of the buy order based on the initial lot size and a doubling strategy.

    • Sell Condition: Conversely, if both indicators suggest the market is overbought (above a certain level), and there are no open sell orders, the script places a sell order, again calculating the lot size with the doubling strategy.

  5. Order Closure: The script has two functions for closing orders:

    • Close All: This function closes all open orders of a specific type (buy or sell). Before closing, it checks the profit of the order. If the order is profitable it resets the "pos" to zero otherwise it adds a 1. The "pos" indicates the amount of loss and is used to increase the lot size in the next trade.

    • Close: This function closes all open orders that made a profit and if the difference between the order open and close price is higher than a limit. This means that the trade was very profitable. In these cases the value of "pos" is increased by 2.

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Commodity channel indexMACD Histogram
12 Views
0 Downloads
0 Favorites
DoubleUp2
//+------------------------------------------------------------------+
//|                                                     DoubleUp2.mq4 |
//|                                                  The # one Lotfy |
//|                                             hmmlotfy@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "The # one Lotfy"
#property link      "hmmlotfy@hotmail.com"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
double ma;
double ma2;
int buyTotal = 0;
int sellTotal = 0;
double lot = 0.1;
int pos = 0;
extern int period= 8;
double buyLevel = 230;
extern int fast = 13;
extern int slow = 33;
extern double wait = 0;
extern double preWait=2 ;
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   lot = NormalizeDouble(AccountBalance()/50001.0,2);
   if(lot < 0.1)
      lot = 0.1;
   ma = iCCI( Symbol(), 0,period, PRICE_CLOSE, 0);
   ma2 = iMACD(NULL,0,fast,slow,2,PRICE_CLOSE,MODE_MAIN,0)*1000000;
   buyTotal = 0;
   sellTotal = 0;
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)// close all orders
   {
      if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != 343) continue;
      if (OrderType() == OP_BUY)
         buyTotal++;
      else
         sellTotal++;
   }
   if(ma>buyLevel && ma2>buyLevel)
      sell();
   else if(ma<-buyLevel && ma2<-buyLevel)
      buy();
   close();
//----
   return(0);
  }

void buy()
{
   closeAll(OP_SELL);
   if(buyTotal == 0)
      OrderSend(Symbol(),OP_BUY, lot*MathPow(2,pos),
          Ask,2, 0/*Ask-(SL2)*Point*/,0/*Ask+SL3*Point*/, NULL, 343, 0, Blue);
}
void sell()
{
   closeAll(OP_BUY);
   if(sellTotal == 0)
      OrderSend(Symbol(),OP_SELL, lot*MathPow(2,pos),
         Bid,2,0/*Bid+(SL2)*Point*/,0/*Bid-SL3*Point*/, NULL, 343, 0, Red );
}
void closeAll(int op)
{
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)// close all orders
   {
      if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != 343) continue;
      if (OrderType() == op )
      {
         if(OrderProfit()<0)
             pos++;
         else if(OrderProfit()>0)
             pos = 0;
         OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Green);// or OrderClosePrice()
      }
   }
}
void close()
{
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)// close all orders
   {
      if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != 343) continue;
         if(OrderProfit()>0 && MathAbs(OrderOpenPrice()-OrderClosePrice())>120*Point)
         {
            pos+=2;
            OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Green);// or OrderClosePrice()
         }
   }
}

Profitability Reports

USD/CHF Jul 2025 - Sep 2025
0.16
Total Trades 4
Won Trades 3
Lost trades 1
Win Rate 75.00 %
Expected payoff -823.42
Gross Profit 634.89
Gross Loss -3928.55
Total Net Profit -3293.66
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.19
Total Trades 7
Won Trades 5
Lost trades 2
Win Rate 71.43 %
Expected payoff -470.72
Gross Profit 788.08
Gross Loss -4083.09
Total Net Profit -3295.01
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.26
Total Trades 5
Won Trades 4
Lost trades 1
Win Rate 80.00 %
Expected payoff -1222.43
Gross Profit 2120.80
Gross Loss -8232.96
Total Net Profit -6112.16
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.00
Total Trades 4
Won Trades 4
Lost trades 0
Win Rate 100.00 %
Expected payoff 533.56
Gross Profit 2134.24
Gross Loss 0.00
Total Net Profit 2134.24
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.07
Total Trades 4
Won Trades 3
Lost trades 1
Win Rate 75.00 %
Expected payoff -1241.55
Gross Profit 370.91
Gross Loss -5337.11
Total Net Profit -4966.20
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.00
Total Trades 4
Won Trades 4
Lost trades 0
Win Rate 100.00 %
Expected payoff 350.11
Gross Profit 1400.43
Gross Loss 0.00
Total Net Profit 1400.43
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.00
Total Trades 4
Won Trades 4
Lost trades 0
Win Rate 100.00 %
Expected payoff 533.61
Gross Profit 2134.44
Gross Loss 0.00
Total Net Profit 2134.44
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.00
Total Trades 4
Won Trades 4
Lost trades 0
Win Rate 100.00 %
Expected payoff 338.02
Gross Profit 1352.09
Gross Loss 0.00
Total Net Profit 1352.09
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
18.18
Total Trades 4
Won Trades 3
Lost trades 1
Win Rate 75.00 %
Expected payoff 264.34
Gross Profit 1118.90
Gross Loss -61.55
Total Net Profit 1057.35
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.00
Total Trades 4
Won Trades 4
Lost trades 0
Win Rate 100.00 %
Expected payoff 369.24
Gross Profit 1476.94
Gross Loss 0.00
Total Net Profit 1476.94
-100%
-50%
0%
50%
100%

Comments