Author: Bolla 2007
Profit factor:
1.27
Price Data Components
Series array that contains close prices for each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Miscellaneous
It plays sound alerts
9 Views
0 Downloads
0 Favorites
V1+V2_v4
//+-------------------+
//| V1+V2_v4.mq4 |
//+-------------------+                                                         

#property copyright "Bolla 2007"
#property link      "http://www.forex-tsd.com/"

#include <stdlib.mqh>



extern double MinFreeMarginPct= 50;


//inputs esterni
extern double TakeProfitLong     = 27;
extern double TakeProfitShort    = 27;
extern int     DLong             = 20;
extern int     DShort            = 20;
extern double Multiplier         = 2;
extern int    MaxTrades          = 8;
extern int    Slippage           = 3;
extern bool   UseSound           = false;

//variabili globali
string  Name_Expert    = "V1+V2_v4";
double  stopLossB      = 0; 
double  stopLossS      = 0; 
string  NameFileSound  = "alert.wav";
double  InitLots       = 0.01;
double  MaxLot         = 2.56;
int     SL             = 0;
double  sB=0,sS=0;
int c,j;
double LotsB,LotsS,Long,Short;
double LastB=0,LastS=1000; 
extern int     MagicLong=800111;
extern int     MagicShort=800222;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {

  return(0);
  }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
  return(0);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()

   {
   
   if(Bars<1)   {Print("bars less than 1");return(0);}
   
   double   Price=iClose(NULL,0,0);
   
   if (!ExistPositions()) {sB=0; sS=0;}
   int T=0;
   int B=0;  
   for(int i=0;i<OrdersTotal();i++) 
      { 
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderComment()==Name_Expert)   
        { 
        int type=OrderType();
        switch(type)
           {
           case OP_BUY:
              sB=1;
              T++;
              LastB=OrderOpenPrice();
              break;
           case OP_SELL:
              sS=2;
              B++;
              LastS=OrderOpenPrice();
              break;
           }
        }    
      }



   LotsB=InitLots;
   LotsS=InitLots;
   LotsB=MathFloor(LotsB*100)/100;
   LotsS=MathFloor(LotsS*100)/100;
   if (LotsB<0.01) LotsB=0.01;
   if (LotsS<0.01) LotsS=0.01;


   for (j=0;j<T;j++) {LotsB=Multiplier*LotsB;}
   for (j=0;j<B;j++) {LotsS=Multiplier*LotsS;}

   if (AccountBalance()>10000) MaxLot=25.6;
   if (LotsB>MaxLot) LotsB=MaxLot; 
   if (LotsS>MaxLot) LotsS=MaxLot; 
   if (LotsB>2.56) LotsB=0.1; 
   if (LotsS>2.56) LotsS=0.1; 


   if (T==0) { Long=1000;}
   if (B==0) {Short=-1000;}
   if ((T>0)||(B>0))
      {
      if ((sB==1)&&(Long>LastB)) Long=LastB;
      if ((sS==2)&&(Short<LastS)) Short=LastS;
      }

   if ((T==MaxTrades)||(B==MaxTrades)) c=1;
   if ((T==0)||(B==0)) c=0;


   double spread=(Ask-Bid)/Point;

   if ((sB==0)&&(c==0))  {OpenBuy();sB=1;} 
   if ((sS==0)&&(c==0))  {OpenSell();sS=2;}   

   if ((T<MaxTrades)&&(B<MaxTrades))
      {
      if ((sB==1)&&(Price<=(LastB-(DLong+spread)*Point))&&(c==0))   {OpenBuy();sB=1;return(0);}
      if ((sS==2)&&(Price>=(LastS+(DShort)*Point))&&(c==0))         {OpenSell();sS=2;return(0);}
      if ((sB==1)&&(Price>=(Long+TakeProfitLong*Point))&&(AccountProfit()>0))          {closeAllOrders(0);sB=0;return(0);}
      if ((sS==2)&&(Price<=(Short-(TakeProfitShort+spread)*Point))&&(AccountProfit()>0)) {closeAllOrders(1);sS=0;return(0);} 
      }
  return (0);
}


// - - - - - - FUNZIONI - - - - - - -


 

bool ExistPositions()
   {
   for(int i=0;i<OrdersTotal(); i++)
      {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderComment()==Name_Expert) return(True);
         else return(false);
      }   
}

void OpenBuy()
   { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLotB(); 
    if (stopLossB==0) { ldStop=0; }
	else {ldStop = Bid+Point*stopLossB; }
   ldTake = NormalizeDouble(GetTakeProfitBuy(),Digits); 
   lsComm = GetCommentForOrder();
   
 
   if (AccountFreeMargin()< (AccountBalance()*(MinFreeMarginPct/100))){
   Print("Cannot Trade Because the Margin is Lower Than ",MinFreeMarginPct,"%");}

   OrderSend(Symbol(),OP_BUY,ldLot,NormalizeDouble(Ask,Digits),Slippage,ldStop,ldTake,lsComm,MagicLong,0,NULL);

   if (UseSound) PlaySound(NameFileSound);
   
}
 
void OpenSell()
   { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLotS();
   if (stopLossS==0) { ldStop=0; }
	else {ldStop = Bid+Point*stopLossS; }
   ldTake = NormalizeDouble(GetTakeProfitSell(),Digits); 
   lsComm = GetCommentForOrder();
   
   
   if (AccountFreeMargin()< (AccountBalance()*(MinFreeMarginPct/100))){
   Print("Cannot Trade Because the Margin is Lower Than ",MinFreeMarginPct,"%");}
   
   OrderSend(Symbol(),OP_SELL,ldLot,NormalizeDouble(Bid,Digits),Slippage,ldStop,ldTake,lsComm,MagicShort,0,NULL); 

   if (UseSound) PlaySound(NameFileSound);
   
}

void closeAllOrders(int type)
   {
   for(int c=0;c<OrdersTotal();c++)
      {
      OrderSelect(c,SELECT_BY_POS,MODE_TRADES); 
      if (OrderSymbol()==Symbol() && OrderComment()==Name_Expert && OrderType()==OP_BUY && type==0)
         {
         OrderClose(OrderTicket(), OrderLots(), Bid,Slippage, White);
         }
      if (OrderSymbol()==Symbol() && OrderComment()==Name_Expert && OrderType()==OP_SELL && type==1)
         {
         OrderClose(OrderTicket(), OrderLots(), Ask,Slippage, White);
         }   
      if (OrderSymbol()==Symbol() && OrderComment()==Name_Expert && OrderType() > 1)  {OrderDelete(OrderTicket());
      }
   }
} 




string GetCommentForOrder() {return(Name_Expert);} 
double GetSizeLotB() {return(LotsB);} 
double GetSizeLotS() {return(LotsS);} 
double GetTakeProfitBuy() {return(Ask+TakeProfitLong*Point);} 
double GetTakeProfitSell() {return(Bid-TakeProfitShort*Point);} 


Profitability Reports

AUD/USD Jul 2025 - Sep 2025
9.59
Total Trades 914
Won Trades 623
Lost trades 291
Win Rate 68.16 %
Expected payoff 3.75
Gross Profit 3829.64
Gross Loss -399.40
Total Net Profit 3430.24
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
8.84
Total Trades 1080
Won Trades 736
Lost trades 344
Win Rate 68.15 %
Expected payoff 3.68
Gross Profit 4482.55
Gross Loss -506.88
Total Net Profit 3975.67
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
3.76
Total Trades 1170
Won Trades 804
Lost trades 366
Win Rate 68.72 %
Expected payoff 4.00
Gross Profit 6380.95
Gross Loss -1698.36
Total Net Profit 4682.59
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
2.97
Total Trades 281
Won Trades 170
Lost trades 111
Win Rate 60.50 %
Expected payoff 2.75
Gross Profit 1166.00
Gross Loss -392.43
Total Net Profit 773.57
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
2.56
Total Trades 677
Won Trades 435
Lost trades 242
Win Rate 64.25 %
Expected payoff 2.37
Gross Profit 2626.95
Gross Loss -1025.82
Total Net Profit 1601.13
-100%
-50%
0%
50%
100%
GBP/CAD Oct 2024 - Jan 2025
2.27
Total Trades 277
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 2.43
Gross Profit 1202.87
Gross Loss -529.75
Total Net Profit 673.12
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
1.96
Total Trades 936
Won Trades 618
Lost trades 318
Win Rate 66.03 %
Expected payoff 2.70
Gross Profit 5162.18
Gross Loss -2631.35
Total Net Profit 2530.83
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.09
Total Trades 6054
Won Trades 4222
Lost trades 1832
Win Rate 69.74 %
Expected payoff 0.22
Gross Profit 16508.85
Gross Loss -15148.55
Total Net Profit 1360.30
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.54
Total Trades 1678
Won Trades 1155
Lost trades 523
Win Rate 68.83 %
Expected payoff -3.47
Gross Profit 6901.83
Gross Loss -12728.14
Total Net Profit -5826.31
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.49
Total Trades 829
Won Trades 558
Lost trades 271
Win Rate 67.31 %
Expected payoff -3.44
Gross Profit 2795.77
Gross Loss -5648.04
Total Net Profit -2852.27
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.42
Total Trades 1310
Won Trades 902
Lost trades 408
Win Rate 68.85 %
Expected payoff -6.66
Gross Profit 6241.16
Gross Loss -14969.56
Total Net Profit -8728.40
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.31
Total Trades 1602
Won Trades 1117
Lost trades 485
Win Rate 69.73 %
Expected payoff -5.84
Gross Profit 4159.94
Gross Loss -13523.52
Total Net Profit -9363.58
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.18
Total Trades 265
Won Trades 173
Lost trades 92
Win Rate 65.28 %
Expected payoff -18.70
Gross Profit 1107.08
Gross Loss -6061.54
Total Net Profit -4954.46
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.09
Total Trades 222
Won Trades 146
Lost trades 76
Win Rate 65.77 %
Expected payoff -42.17
Gross Profit 883.79
Gross Loss -10246.51
Total Net Profit -9362.72
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.08
Total Trades 193
Won Trades 121
Lost trades 72
Win Rate 62.69 %
Expected payoff -46.73
Gross Profit 826.73
Gross Loss -9846.40
Total Net Profit -9019.67
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.08
Total Trades 749
Won Trades 534
Lost trades 215
Win Rate 71.30 %
Expected payoff -39.15
Gross Profit 2596.21
Gross Loss -31917.75
Total Net Profit -29321.54
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.07
Total Trades 685
Won Trades 490
Lost trades 195
Win Rate 71.53 %
Expected payoff -43.34
Gross Profit 2171.66
Gross Loss -31858.53
Total Net Profit -29686.87
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.07
Total Trades 230
Won Trades 162
Lost trades 68
Win Rate 70.43 %
Expected payoff -39.21
Gross Profit 707.03
Gross Loss -9725.49
Total Net Profit -9018.46
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.06
Total Trades 241
Won Trades 164
Lost trades 77
Win Rate 68.05 %
Expected payoff -37.42
Gross Profit 539.06
Gross Loss -9557.65
Total Net Profit -9018.59
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.06
Total Trades 67
Won Trades 35
Lost trades 32
Win Rate 52.24 %
Expected payoff -73.78
Gross Profit 318.60
Gross Loss -5261.79
Total Net Profit -4943.19
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.05
Total Trades 165
Won Trades 100
Lost trades 65
Win Rate 60.61 %
Expected payoff -56.75
Gross Profit 467.97
Gross Loss -9830.92
Total Net Profit -9362.95
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.01
Total Trades 71
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -134.56
Gross Profit 144.05
Gross Loss -9697.83
Total Net Profit -9553.78
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.01
Total Trades 69
Won Trades 46
Lost trades 23
Win Rate 66.67 %
Expected payoff -130.71
Gross Profit 130.87
Gross Loss -9149.61
Total Net Profit -9018.74
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.01
Total Trades 2391
Won Trades 1697
Lost trades 694
Win Rate 70.97 %
Expected payoff -691.27
Gross Profit 8551.17
Gross Loss -1661388.51
Total Net Profit -1652837.34
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.01
Total Trades 39
Won Trades 21
Lost trades 18
Win Rate 53.85 %
Expected payoff -204.14
Gross Profit 83.12
Gross Loss -8044.69
Total Net Profit -7961.57
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.01
Total Trades 29
Won Trades 13
Lost trades 16
Win Rate 44.83 %
Expected payoff -311.96
Gross Profit 62.19
Gross Loss -9109.16
Total Net Profit -9046.97
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.00
Total Trades 17
Won Trades 5
Lost trades 12
Win Rate 29.41 %
Expected payoff -550.81
Gross Profit 2.89
Gross Loss -9366.64
Total Net Profit -9363.75
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.00
Total Trades 2208
Won Trades 1553
Lost trades 655
Win Rate 70.34 %
Expected payoff -1131.95
Gross Profit 9056.16
Gross Loss -2508411.89
Total Net Profit -2499355.73
-100%
-50%
0%
50%
100%

Comments