Author: Copyright � 2007, Yury V. Reshetov
Profit factor:
2.19
Orders Execution
Checks for the total of closed ordersChecks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
6 Views
0 Downloads
0 Favorites
Swaper_1.1
//+------------------------------------------------------------------+
//|                                                   Swaper_1.1.mq4 |
//|                               Copyright © 2007, Yury V. Reshetov |
//|                                          http://reshetov.xnet.uz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Yury V. Reshetov"
#property link      "http://reshetov.xnet.uz"
//---- input parameters
extern double experts = 1;
extern double beginPrice = 1.8014;
extern int    magicnumber = 777;
static int    prevtime = 0;
static double bl = 1000;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   if(Time[0] == prevtime) 
       return(0);
   prevtime = Time[0];
   if(!IsTradeAllowed()) 
     {
       prevtime = Time[1];
       return(0);
     }
//----
   int total = OrdersHistoryTotal();
   double money = bl * beginPrice;
   int i = 0;
   for (i = 0; i < total; i++) 
     {
       OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == magicnumber) 
         {
           if(OrderType() == OP_BUY) 
             {
               money = money + (OrderClosePrice() - 
                       OrderOpenPrice()) * 10 * OrderLots();
             } 
           else 
             {
               money = money - (OrderClosePrice() - 
                       OrderOpenPrice()) * 10 * OrderLots();
             }
         }
     }
   total = OrdersTotal();   
   double com =  bl;
   int tickbuy = -1;
   double buyvolume = 0;
   int ticksell = -1;
   double sellvolume = 0;
   for(i = 0; i < total; i++) 
     {
       OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
       if(OrderMagicNumber() == magicnumber) 
         {
           if(OrderType() == OP_BUY) 
             {
               if(OrderSymbol() == Symbol()) 
                 {
                   money = money - 10 * buyvolume * OrderOpenPrice();
                   if ((MarketInfo(Symbol(), MODE_SWAPLONG) < 0) || (AccountFreeMargin() < 0 && OrderProfit() < 0)) {
                     buyvolume = OrderLots();
                     tickbuy = OrderTicket();
                   } 
                 }
               com = com + 10 * OrderLots(); 
             } 
           else 
             {
               if(OrderSymbol() == Symbol()) 
                 {
                   money = money + 10 * sellvolume * OrderOpenPrice();
                   if ((MarketInfo(Symbol(), MODE_SWAPSHORT) < 0) || (AccountFreeMargin() < 0 && OrderProfit() < 0)) {
                     sellvolume = OrderLots();
                     ticksell = OrderTicket();
                   }
                 }
               com = com - 10 * OrderLots(); 
             }
         }
     }
      
   double fv = money / com;
   Comment("Fair value ", fv);
   
   if(! IsTradeAllowed()) 
     {
       prevtime = Time[1];
       return(0);
     }
   closeby(ticksell, tickbuy);
   if(!IsTradeAllowed()) 
     {
       prevtime = Time[1];
       return(0);
     }
   double lots = 0;
   double price = 0;
   double dt = (money / (MathMax(High[1], High[0]) + MarketInfo(Symbol(), MODE_SPREAD) * Point) - com) * experts / (experts + 1);
   if(dt < 0) 
     {
       dt = (com - money / MathMin(Low[1], Low[0])) * experts / (experts + 1);
       if(dt < 1) 
         {
           closeby(tickbuy, ticksell);
           return(0);
         }
       lots = MathFloor(dt) / 10;
       if(tickbuy >= 0) 
         {
           if(buyvolume > lots) 
             {
               OrderClose(tickbuy, lots, Bid, 3, Blue);
               Sleep(30000);
             } 
           else 
             {
               OrderClose(tickbuy, buyvolume, Bid, 3, Blue);
               tickbuy = -1;
               Sleep(30000);
             }
         } 
       else 
         {
           lots = getLots(lots);
           if(lots > 0) 
             {
               ticksell = OrderSend(Symbol(), OP_SELL, lots, Bid, 3, 
                          0, 0, "Swaper", magicnumber, 0, Red);
               Sleep(30000);
             }
         }
     } 
   else 
     {
       if(dt < 1) 
         {
           closeby(ticksell, tickbuy);
           return(0);
         }
       lots = MathFloor(dt) / 10;
       if(ticksell >= 0) 
         {
           if(sellvolume > lots) 
             {
               OrderClose(ticksell, lots, Ask, 3, Red);
               Sleep(30000);
             } 
           else 
             {
               OrderClose(ticksell, sellvolume, Ask, 3, Red);
               ticksell = -1;
               Sleep(30000);
             }
         } 
       else 
         {
           lots = getLots(lots);
           if(lots > 0) 
             {
               tickbuy = OrderSend(Symbol(), OP_BUY, lots, Ask, 3, 0, 
                         0, "Swaper",  magicnumber, 0, Blue);
               Sleep(30000);
             }
         }
     }
//----
   if(!IsTradeAllowed()) 
     {
       prevtime = Time[1];
       return(0);
     }
   closeby(tickbuy, ticksell);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void closeby(int sell, int buy) 
  {
   if(sell >= 0 && buy >= 0) 
     {
       OrderCloseBy(buy, sell, Green);
       Sleep(30000);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double getLots(double lt) 
  {
   double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   double freemargin = AccountFreeMargin();
   if(freemargin > (marginrequired * lt)) 
     {
       return(lt);
     } 
   double result = freemargin / marginrequired;
   result = MathFloor(result * 10) / 10;
   return(result);
  }
//+------------------------------------------------------------------+

Profitability Reports

USD/CAD Jul 2025 - Sep 2025
0.00
Total Trades 9
Won Trades 0
Lost trades 9
Win Rate 0.00 %
Expected payoff -217.83
Gross Profit 0.00
Gross Loss -1960.46
Total Net Profit -1960.46
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.00
Total Trades 1
Won Trades 0
Lost trades 1
Win Rate 0.00 %
Expected payoff -8336.60
Gross Profit 0.00
Gross Loss -8336.60
Total Net Profit -8336.60
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
10.57
Total Trades 5
Won Trades 3
Lost trades 2
Win Rate 60.00 %
Expected payoff 241.64
Gross Profit 1334.40
Gross Loss -126.20
Total Net Profit 1208.20
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
1.69
Total Trades 98
Won Trades 54
Lost trades 44
Win Rate 55.10 %
Expected payoff 33.67
Gross Profit 8070.82
Gross Loss -4770.77
Total Net Profit 3300.05
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.00
Total Trades 5
Won Trades 0
Lost trades 5
Win Rate 0.00 %
Expected payoff -1011.32
Gross Profit 0.00
Gross Loss -5056.59
Total Net Profit -5056.59
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 1
Won Trades 0
Lost trades 1
Win Rate 0.00 %
Expected payoff -1452.00
Gross Profit 0.00
Gross Loss -1452.00
Total Net Profit -1452.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.00
Total Trades 1
Won Trades 0
Lost trades 1
Win Rate 0.00 %
Expected payoff -750.00
Gross Profit 0.00
Gross Loss -750.00
Total Net Profit -750.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.00
Total Trades 1
Won Trades 0
Lost trades 1
Win Rate 0.00 %
Expected payoff -382.17
Gross Profit 0.00
Gross Loss -382.17
Total Net Profit -382.17
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.00
Total Trades 1
Won Trades 0
Lost trades 1
Win Rate 0.00 %
Expected payoff -353.86
Gross Profit 0.00
Gross Loss -353.86
Total Net Profit -353.86
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.04
Total Trades 15
Won Trades 2
Lost trades 13
Win Rate 13.33 %
Expected payoff -247.44
Gross Profit 136.49
Gross Loss -3848.10
Total Net Profit -3711.61
-100%
-50%
0%
50%
100%

Comments