MartingailExpert

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

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
10 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/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%
GBP/USD Jan 2025 - Jul 2025
3.12
Total Trades 44
Won Trades 32
Lost trades 12
Win Rate 72.73 %
Expected payoff 236.30
Gross Profit 15307.30
Gross Loss -4910.20
Total Net Profit 10397.10
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
6.10
Total Trades 59
Won Trades 46
Lost trades 13
Win Rate 77.97 %
Expected payoff 471.94
Gross Profit 33300.40
Gross Loss -5455.97
Total Net Profit 27844.43
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
6.49
Total Trades 54
Won Trades 45
Lost trades 9
Win Rate 83.33 %
Expected payoff 313.27
Gross Profit 19995.49
Gross Loss -3078.97
Total Net Profit 16916.52
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
4.13
Total Trades 43
Won Trades 33
Lost trades 10
Win Rate 76.74 %
Expected payoff 389.03
Gross Profit 22072.00
Gross Loss -5343.50
Total Net Profit 16728.50
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.00
Total Trades 27
Won Trades 0
Lost trades 27
Win Rate 0.00 %
Expected payoff -128.26
Gross Profit 0.00
Gross Loss -3462.90
Total Net Profit -3462.90
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
4.87
Total Trades 85
Won Trades 70
Lost trades 15
Win Rate 82.35 %
Expected payoff 1322.17
Gross Profit 141436.65
Gross Loss -29052.04
Total Net Profit 112384.61
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
2.20
Total Trades 51
Won Trades 36
Lost trades 15
Win Rate 70.59 %
Expected payoff 217.86
Gross Profit 20398.00
Gross Loss -9287.10
Total Net Profit 11110.90
-100%
-50%
0%
50%
100%

Comments