MultiPairWPRtrails

Author: WPR for Multi Pair, Copyright � 2005, Gary Hensley
Profit factor:
0.45
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Indicators Used
Larry William percent range indicator
8 Views
0 Downloads
0 Favorites
MultiPairWPRtrails
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+-----------------------------------------+
//|GH.mq4   WPR for Multi Pair              |
//|Copyright © 2005, Gary Hensley           |
//+-----------------------------------------+
//
//		Modifications                                                         
//		-------------                                                       
//		DATE       	MOD #    	DESCRIPTION                		        
//		---------- 	-------- 	---------------------------------------------------------------
//		01 Jul 2005 1   		   GaryH: Converted Original M3 version of MultiPairWPR script.

#property copyright "WPR for Multi Pair, Copyright © 2005, Gary Hensley"
//#property link      "http://www.metaquotes.net/"

#define MAGICMA  20050610

//---- input parameters
extern int       UsePct=0;
extern int       MaxLots=100;
extern int TrailingStop=20;
extern int ProfitTarget=100;
extern int Slippage=3;
//---- global variables
int bsi=0;
int dir=0;
int vTrig=0;
int openorders=0;
string pair;
double vSL=0,vTP=0;
int dummy=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   pair = Symbol();
   return(0);
  } 

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

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int GetCurrentOrders()
  {
  //---- calc open OrderSelect
   openorders=0;
   dir=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      //if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
      if(OrderSymbol()==Symbol())
      {
        openorders+=1;
        if(OrderType()==OP_BUY) dir=1;
        if(OrderType()==OP_SELL) dir=-1;
      }  
   }
}

//+------------------------------------------------------------------+
//| Calculate Lot Sizes                                              |
//+------------------------------------------------------------------+
int LotCalc(double Risk)
  {
   int vLots=0;
   if (UsePct >0 && Risk>0) vLots=MathFloor(AccountBalance()*(UsePct/100)/((Risk/MarketInfo (Symbol(), MODE_POINT))*10));
   if (UsePct >0 && Risk==0)  vLots = MathFloor(AccountBalance()*(UsePct/100)/1000);
   if (vLots>MaxLots) vLots=MaxLots;
   if (vLots<1) vLots=1;
   vLots=0.1;
   return(vLots);
}

//+------------------------------------------------------------------+
//| Close Open Position                                              |
//+------------------------------------------------------------------+
int CloseTrade()
  { 
  for(int i=0;i<OrdersTotal();i++)
    {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      //if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      if(OrderSymbol()==Symbol())
      {
        if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
        if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
      }  
  }
}

//+------------------------------------------------------------------+
//| Open Trade Position                                              |
//+------------------------------------------------------------------+
int OpenTrade()
  {
  // int vLots=LotCalc(0);
      double vLots=0.1;

   if (bsi>0) OrderSend(Symbol(),OP_BUY,vLots,Ask,3,0,0,0,0,Blue);
   if (bsi<0) OrderSend(Symbol(),OP_SELL,vLots,Bid,3,0,0,0,0,Red);
}

//+------------------------------------------------------------------+
//| Buy/Sell Indicator                                               |
//+------------------------------------------------------------------+
int CalcBSI()
  {
  //---- calc current indicators
  int GU_Trig=1,EU_Trig=1,UC_Trig=1,UJ_Trig=1;
  if (iWPR("GBPUSD",0,14,0)<-50) GU_Trig=-1;
  if (iWPR("EURUSD",0,14,0)<-50) EU_Trig=-1;
  if (iWPR("USDCHF",0,14,0)<-50) UC_Trig=-1;
  if (iWPR("USDJPY",0,14,0)<-50) UJ_Trig=-1;
  vTrig=GU_Trig+EU_Trig-UC_Trig-UJ_Trig;

  bsi=0;
  if (vTrig>2) bsi=1;
  if (vTrig<-2) bsi=-1;
  if (pair>"USD") bsi=bsi*(-1);

}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
 // if (Hour()<7) return(0);
  GetCurrentOrders();
  CalcBSI();
  Comment("Dir: ",dir,"\nBSI: ",bsi,"\nTrig: ",vTrig);
     HandleOpenTrades();

  //---- exit trades
  if (openorders!=0) {
     if ((bsi>0) && (dir<0)) CloseTrade();
     if ((bsi<0) && (dir>0)) CloseTrade();
  }   
  //---- open trades
  else {
   if (bsi!=0) OpenTrade();
  }   
}
void HandleOpenTrades()
  {
   for (int i = 0; i < OrdersTotal(); i++)
   {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
 
      if (OrderSymbol() == Symbol())
      {
        if (OrderType() == OP_BUY )
        {
          if( dummy !=0)
          {      
             OrderClose(OrderTicket(), OrderLots(), Bid, Slippage);
             return(0);
          }
          else
          {
            if (TrailingStop > 0)
            {
	           if (Ask - OrderOpenPrice() > TrailingStop * Point)
  	  	        {
		          if (OrderStopLoss() < Ask - TrailingStop * Point)
		          {
	               OrderModify(OrderTicket(), OrderOpenPrice(), Ask - TrailingStop * Point, Ask + ProfitTarget * Point, 0);
                  return(0);
                }
              }
            }
          }
        }
        if (OrderType() == OP_SELL )
        {
          if( dummy !=0)
          {
            OrderClose(OrderTicket(), OrderLots(), Ask, Slippage);
            return(0);
          }
          else
          {
            if (TrailingStop > 0)
            {
              if (OrderOpenPrice() - Bid > TrailingStop * Point)
              {
                if (OrderStopLoss() > Bid + TrailingStop * Point)
                {
                  OrderModify(OrderTicket(), OrderOpenPrice(), Bid + TrailingStop * Point, Bid - ProfitTarget * Point, 0);
                  return(0);
                }
	  	        }
            }
          }
          
        }    
      }
   }
 }

Profitability Reports

USD/JPY Jul 2025 - Sep 2025
0.84
Total Trades 896
Won Trades 771
Lost trades 125
Win Rate 86.05 %
Expected payoff -0.48
Gross Profit 2280.05
Gross Loss -2709.43
Total Net Profit -429.38
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.64
Total Trades 79
Won Trades 24
Lost trades 55
Win Rate 30.38 %
Expected payoff -9.73
Gross Profit 1392.60
Gross Loss -2161.20
Total Net Profit -768.60
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.59
Total Trades 71
Won Trades 26
Lost trades 45
Win Rate 36.62 %
Expected payoff -5.19
Gross Profit 536.28
Gross Loss -904.91
Total Net Profit -368.63
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.58
Total Trades 472
Won Trades 348
Lost trades 124
Win Rate 73.73 %
Expected payoff -1.65
Gross Profit 1094.30
Gross Loss -1871.50
Total Net Profit -777.20
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.57
Total Trades 689
Won Trades 554
Lost trades 135
Win Rate 80.41 %
Expected payoff -2.15
Gross Profit 2003.50
Gross Loss -3484.70
Total Net Profit -1481.20
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.51
Total Trades 497
Won Trades 374
Lost trades 123
Win Rate 75.25 %
Expected payoff -1.87
Gross Profit 958.00
Gross Loss -1888.30
Total Net Profit -930.30
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.29
Total Trades 158
Won Trades 33
Lost trades 125
Win Rate 20.89 %
Expected payoff -13.10
Gross Profit 857.15
Gross Loss -2927.10
Total Net Profit -2069.95
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.28
Total Trades 789
Won Trades 674
Lost trades 115
Win Rate 85.42 %
Expected payoff -1.26
Gross Profit 393.76
Gross Loss -1386.61
Total Net Profit -992.85
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.23
Total Trades 842
Won Trades 705
Lost trades 137
Win Rate 83.73 %
Expected payoff -2.78
Gross Profit 716.20
Gross Loss -3057.34
Total Net Profit -2341.14
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 78
Won Trades 61
Lost trades 17
Win Rate 78.21 %
Expected payoff -1353.54
Gross Profit 153.60
Gross Loss -105729.80
Total Net Profit -105576.20
-100%
-50%
0%
50%
100%

Comments