MartingailExpert

Author: Copyright � 2007, MetaQuotes Software Corp.
Profit factor:
2.38

Here's an explanation of what this trading script does, avoiding technical jargon and focusing on the core logic:

This script is designed to automatically trade in the financial markets based on certain conditions. It's like having a robot that places buy and sell orders for you.

Here's the breakdown of what the script does:

  1. Setup (Initialization): When the script starts, it prepares itself. It doesn't do much in the initial setup, but it's ready to go.

  2. Closing Orders (Take Profit): The script constantly watches existing open trades.

    • If you have a "buy" order and the price goes high enough (reaching a profit target), the script automatically closes that order to secure your profit.
    • Similarly, if you have a "sell" order and the price goes low enough (reaching a profit target), the script closes the order to secure the profit.
  3. Margin Check: The script checks if there's enough available money in the trading account to cover potential losses. If the available margin is low, the script stops opening new trades to avoid running out of funds.

  4. Opening Initial Orders: If there aren't any trades currently open, the script looks for opportunities to buy or sell based on an indicator called "Stochastic Oscillator". The Stochastic Oscillator is used as a signal of overbought or oversold conditions:

    • If the Stochastic Oscillator suggests the market is "oversold" (likely to go up), the script places a "buy" order.
    • If the Stochastic Oscillator suggests the market is "overbought" (likely to go down), the script places a "sell" order.
  5. Adding to Existing Orders (Martingale-like): If a trade is already open:

    • If you have a "buy" order, and the price goes higher it does the same of closing orders (see item 2).
    • If you have a "buy" order and the price goes against you (goes down), the script opens another "buy" order. The size of the new order is bigger than the original, using a multiplying factor to try and recover potential losses quickly when the price eventually goes back up.
    • The same logic applies to "sell" orders, but in the opposite direction. If the price goes up against the "sell" order, the script opens another, larger "sell" order.
  6. Calculating Profit Targets: After an order is open, the script calculates the "take profit" level, where it will automatically close the trade to secure a profit. The target take profit is bigger with bigger ammount of opened orders.

  7. Displaying Information: The script displays information on the chart, such as the total number of open trades, the total size of all trades, and the calculated profit levels. It also shows the free margin and account balance.

In simple terms: This script tries to make money by automatically buying and selling, aiming to close trades for a profit when prices move in the desired direction. When prices move against the script, it tries to compensate by opening additional, larger orders.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Stochastic oscillator
12 Views
1 Downloads
0 Favorites
MartingailExpert
//+------------------------------------------------------------------+
//|                                                          aaa.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double step=25;
extern double proffactor=9;
extern double mult=1.6;
extern double lots=0.3;  
extern double per_K=20;
extern double per_D=6;
extern double slow=6;
extern double zoneBUY=50;
extern double zoneSELL=50;
double openprice,ask,n,lots2,tp,total,cnt,sm,rtpbay,rtpsell,free,balance;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
if (Ask>=openprice+tp*Point)
for(cnt = OrdersTotal(); cnt >= 0; cnt--)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderSymbol() == Symbol())
         {
           if(OrderType() == OP_BUY)
             {
              OrderClose(OrderTicket(), OrderLots(), Ask, 3, Yellow);lots2=lots;
             }
         }
     }
if (Bid<=openprice-tp*Point)
for(cnt = OrdersTotal(); cnt >= 0; cnt--)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderSymbol() == Symbol())
         {
           if(OrderType() == OP_SELL)
             {
              OrderClose(OrderTicket(), OrderLots(), Bid, 3, Yellow);lots2=lots;
             }
         }
     }
free=AccountFreeMargin();balance=AccountBalance();
if (AccountFreeMargin()<=AccountBalance()/2)return(0);  
total=OrdersTotal();
    if(total<1)
    {  
    if(iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,0,1)>iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)
      && iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)>zoneBUY)             
        n=OrderSend(Symbol(),OP_BUY,lots,Ask,3,0,0,"",0,0,Green);       
    if(iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,0,1)<iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)
      && iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)<zoneSELL)      
        n=OrderSend(Symbol(),OP_SELL,lots,Bid,3,0,0,"",0,0,Red);
    }
total=OrdersTotal();
OrderSelect(n,SELECT_BY_TICKET, MODE_TRADES);
openprice=OrderOpenPrice();
  if(total>0)
  {
   if(OrderType() == OP_BUY)
     {
      if (Ask>=openprice+tp*Point)lots2=lots;
      if (Ask>=openprice+tp*Point)n=OrderSend(Symbol(),OP_BUY,lots2,Ask,3,0,0,"",0,0,Blue);
      if (Ask<=openprice-step*Point)lots2=lots2*mult;
      if (Ask<=openprice-step*Point)n=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lots2,1),Ask,3,0,0,"",0,0,Blue);
     }
   if(OrderType() == OP_SELL)
     {
      if (Bid<=openprice-tp*Point)lots2=lots;
      if (Bid<=openprice-tp*Point)n=OrderSend(Symbol(),OP_SELL,lots2,Bid,3,0,0,"",0,0,Red);
      if (Bid>=openprice+step*Point)lots2=lots2*mult;
      if (Bid>=openprice+step*Point)n=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lots2,1),Bid,3,0,0,"",0,0,Red);
     }
  }
total=OrdersTotal();
OrderSelect(n,SELECT_BY_TICKET, MODE_TRADES);
openprice=OrderOpenPrice();
if (total>0) tp=total*proffactor;
rtpbay=openprice+tp*Point;rtpsell=openprice-tp*Point;
{
   double sm;
   total = OrdersTotal();
   for(cnt = 0; cnt < total; cnt++)
     {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);     
         {                
          sm = sm + OrderLots();  
         } 
     }   
   Comment("Total = ",total,"  Lot = ",sm,"  TakeProfitSell = ",rtpsell,"  TakeProfitBay = ",rtpbay,
   "  FreeMargin = ",free,"  Balance = ",balance);
}

//----
   return(0);
  }
//+------------------------------------------------------------------+

Profitability Reports

USD/CAD Jul 2025 - Sep 2025
0.00
Total Trades 18
Won Trades 0
Lost trades 18
Win Rate 0.00 %
Expected payoff -272.36
Gross Profit 0.00
Gross Loss -4902.56
Total Net Profit -4902.56
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.01
Total Trades 27
Won Trades 1
Lost trades 26
Win Rate 3.70 %
Expected payoff -158.27
Gross Profit 45.00
Gross Loss -4318.30
Total Net Profit -4273.30
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.20
Total Trades 33
Won Trades 21
Lost trades 12
Win Rate 63.64 %
Expected payoff 13.65
Gross Profit 2682.40
Gross Loss -2232.10
Total Net Profit 450.30
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.00
Total Trades 9
Won Trades 0
Lost trades 9
Win Rate 0.00 %
Expected payoff -549.71
Gross Profit 0.00
Gross Loss -4947.38
Total Net Profit -4947.38
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.00
Total Trades 9
Won Trades 0
Lost trades 9
Win Rate 0.00 %
Expected payoff -548.94
Gross Profit 0.00
Gross Loss -4940.48
Total Net Profit -4940.48
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.00
Total Trades 22
Won Trades 0
Lost trades 22
Win Rate 0.00 %
Expected payoff -175.61
Gross Profit 0.00
Gross Loss -3863.50
Total Net Profit -3863.50
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.00
Total Trades 14
Won Trades 0
Lost trades 14
Win Rate 0.00 %
Expected payoff -307.66
Gross Profit 0.00
Gross Loss -4307.29
Total Net Profit -4307.29
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
3.52
Total Trades 34
Won Trades 23
Lost trades 11
Win Rate 67.65 %
Expected payoff 140.68
Gross Profit 6682.62
Gross Loss -1899.56
Total Net Profit 4783.06
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.00
Total Trades 28
Won Trades 0
Lost trades 28
Win Rate 0.00 %
Expected payoff -147.01
Gross Profit 0.00
Gross Loss -4116.18
Total Net Profit -4116.18
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
2.62
Total Trades 42
Won Trades 30
Lost trades 12
Win Rate 71.43 %
Expected payoff 276.14
Gross Profit 18771.30
Gross Loss -7173.60
Total Net Profit 11597.70
-100%
-50%
0%
50%
100%

Comments