priorities comp final

Author: Copyright � 2007, Paul Brodar
Profit factor:
0.00
Price Data Components
Series array that contains close prices for each barSeries array that contains tick volumes of each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
1 Views
0 Downloads
0 Favorites
priorities comp final
//+------------------------------------------------------------------+
//|                                                  priorities.mq4 |
//|                                    Copyright © 2007, Paul Brodar |
//|                                              brodar2012@yahoo.com|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Paul Brodar"
#property link      ""

//-----------Expert Identifers----------------------------------------
static string  Name="Priorities";
static int MagicExpert=87000; // Bare
//--------------------------------------------------------------------

//---- input parameters

//+------------------------------------------------------------------+

static double     MaximumRisk      = 4.5;  
static double     MaxNumberOfTrades=3;
static int Multiplier=4;
static int     MaxPerDirection=1;
static double  Lots;
static int     LastRan=-1;
int i;
static string CurrencyPair[35][4];//[x][0] is unsorted [x][1]sorted
static double Swap[70];
static double OpenTrades[16][10];
static int Duration=6;
static int NumberOfPairs=12;
static double CurrencyLots[35];
static bool MacUp;
static bool MacDown;

//+------------------------------------------------------------------+
//|Function Run Once Daily                                           |
//+------------------------------------------------------------------+
void RunOnceDaily(int rundate){
   Prioritize();
   if(OrdersTotal()>0) {CheckForClose(1);}
   Lots=lotsize();
   LastRan=rundate;
 }
  
//+------------------------------------------------------------------+
//|Function mac                                                      |
//+------------------------------------------------------------------+
void Mac(string pair){
    MacUp=false; MacDown=false;
    if (MarketInfo(pair,MODE_SWAPLONG)>0)
     if(iClose(pair,1440,1)>iClose(pair,1440,Speed1(pair)))
         if(iClose(pair,60,1)>iClose(pair,60,Speed2(pair)))
          if(iVolume(pair,60,1)>iVolume(pair,60,2))
       

               MacUp=true;
     if (MarketInfo(pair,MODE_SWAPSHORT)>0)
      if(iClose(pair,1440,1)<iClose(pair,1440,Speed1(pair)))
         if(iClose(pair,60,1)<iClose(pair,60,Speed2(pair)))
          if(iVolume(pair,60,1)>iVolume(pair,60,2))
                    MacDown=true;
}
  
  
//+------------------------------------------------------------------+
//|Function Base                                          |
//+------------------------------------------------------------------+
double Base(string Pair){
   
   if (Pair=="GBPJPY")return(2); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="EURAUD")return(1.4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURUSD")return(1.4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURCHF")return(1.4);// return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURGBP")return(1.4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURJPY")return(1.4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="GBPUSD")return(2); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="GBPCHF")return(2); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="AUDUSD") return(2); //return(MarketInfo("AUDUSD",MODE_ASK)*2);
   if (Pair=="USDCHF") return(1);
   if (Pair=="USDJPY") return(1);
   if (Pair=="USDCAD") return(1);
   return(1); 
}

//+------------------------------------------------------------------+
//|Function TP                                          |
//+------------------------------------------------------------------+
double TakeProfit(string Pair){
   
   if (Pair=="GBPJPY")return(180); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="GBPUSD")return(130); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="EURAUD")return(75); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURUSD")return(50); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURCHF")return(50);// return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURGBP")return(50); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURJPY")return(160); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="GBPCHF")return(180); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="AUDUSD") return(85); //return(MarketInfo("AUDUSD",MODE_ASK)*2);
   if (Pair=="USDCHF") return(150);
   if (Pair=="USDJPY") return(90);
   if (Pair=="USDCAD") return(85);
   return(90); 
}//+------------------------------------------------------------------+
//|Function TP                                          |
//+------------------------------------------------------------------+
double Speed1(string Pair){
   
   if (Pair=="GBPJPY")return(3); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="GBPUSD")return(3); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="EURAUD")return(10); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURUSD")return(15); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURCHF")return(12);// return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURGBP")return(4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURJPY")return(3); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="GBPCHF")return(9); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="AUDUSD") return(3); //return(MarketInfo("AUDUSD",MODE_ASK)*2);
   if (Pair=="USDCHF") return(7);
   if (Pair=="USDJPY") return(3);
   if (Pair=="USDCAD") return(8);
   return(3); 
}//+------------------------------------------------------------------+
//|Function TP                                          |
//+------------------------------------------------------------------+
double Speed2(string Pair){
   
   if (Pair=="GBPJPY")return(4); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="GBPUSD")return(4); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="EURAUD")return(4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURUSD")return(12); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURCHF")return(7);// return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURGBP")return(4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="EURJPY")return(4); //return(MarketInfo("EURUSD",MODE_ASK));
   if (Pair=="GBPCHF")return(8); // return(MarketInfo("GBPUSD",MODE_ASK));
   if (Pair=="AUDUSD") return(7); //return(MarketInfo("AUDUSD",MODE_ASK)*2);
   if (Pair=="USDCHF") return(8);
   if (Pair=="USDJPY") return(7);
   if (Pair=="USDCAD") return(11);
   return(4); 
}

//+------------------------------------------------------------------+
//|Function prioritize                                            |
//+------------------------------------------------------------------+
void Prioritize(){
/*  for(i=0;i<34;i++){
      CurrencyLots[i]=0;
      for(int j=0;j<3;j++){
           CurrencyPair[i][j]="";
      }
  }  
   
   CurrencyPair[1][0]= "EURAUD" ;
   CurrencyPair[2][0]= "EURUSD" ;
   CurrencyPair[3][0]= "EURCHF" ;
   CurrencyPair[4][0]= "EURGBP" ;
   CurrencyPair[5][0]= "EURJPY" ;
   CurrencyPair[6][0]= "GBPUSD" ;
   CurrencyPair[7][0]= "GBPJPY" ;
   CurrencyPair[8][0]= "GBPCHF" ;
   CurrencyPair[9][0]= "AUDUSD" ;
   CurrencyPair[10][0]= "USDCHF" ;
   CurrencyPair[11][0]= "USDJPY" ;
   CurrencyPair[12][0]= "USDCAD" ;

   for(int p1=1;p1<=NumberOfPairs;p1++){
       Swap[p1]=MarketInfo(CurrencyPair[p1][0],MODE_SWAPLONG)/Base(CurrencyPair[p1][0]);
       Swap[p1+NumberOfPairs]=MarketInfo(CurrencyPair[p1][0],MODE_SWAPSHORT)/Base(CurrencyPair[p1][0]);
   }
   Swap[0]=-100;
   ArraySort(Swap,NumberOfPairs*2+1,0,MODE_DESCEND);
 
   for(int p2=0;p2<=NumberOfPairs;p2++){
     for(int p3=1;p3<=NumberOfPairs;p3++){
         if(MarketInfo(CurrencyPair[p3][0],MODE_SWAPLONG)/Base(CurrencyPair[p3][0])==Swap[p2]&& CurrencyPair[p3][1]!="Taken"){// 
            CurrencyPair[p3][1]="Taken";
            CurrencyPair[p2][2]=CurrencyPair[p3][0];
         }
         if(MarketInfo(CurrencyPair[p3][0],MODE_SWAPSHORT)/Base(CurrencyPair[p3][0])==Swap[p2]&&CurrencyPair[p3][1]!="Taken"){//
            CurrencyPair[p3][1]="Taken";
            CurrencyPair[p2][2]=CurrencyPair[p3][0];
         }
     }    
   }

   for(int p4=0;p4<=NumberOfPairs;p4++){
      if(MarketInfo(CurrencyPair[p4][2],MODE_SWAPLONG)>=0) CurrencyPair[p4][1]="Long";
        else CurrencyPair[p4][1]="Short";      
   }
*/
   CurrencyPair[0][2]= "AUDUSD" ;
   CurrencyPair[1][2]= "GBPJPY" ;
   CurrencyPair[2][2]= "GBPCHF" ;
   CurrencyPair[3][2]= "EURJPY" ;
   CurrencyPair[4][2]= "USDJPY" ;
   CurrencyPair[5][2]= "EURCHF" ;
   CurrencyPair[6][2]= "EURAUD" ;
   CurrencyPair[7][2]= "EURUSD" ;
   CurrencyPair[8][2]= "USDCAD" ;
   CurrencyPair[9][2]= "USDCHF" ;
   CurrencyPair[10][2]= "EURGBP" ;
   CurrencyPair[11][2]= "GBPUSD" ;

   for(int p1=0;p1<12;p1++){
      CurrencyPair[p1][1]="none";
      if(MarketInfo(CurrencyPair[p1][2],MODE_SWAPLONG)>0)CurrencyPair[p1][1]="Long";
      if(MarketInfo(CurrencyPair[p1][2],MODE_SWAPSHORT)>0)CurrencyPair[p1][1]="Short";
   }


}

//+------------------------------------------------------------------+
//|  FUNCTION Lotsize                         set to max five lots                       |
//+------------------------------------------------------------------+

double lotsize(){
   double lots=1;
   double risk=AccountEquity()*MaximumRisk/10000;
   lots=risk/MaxNumberOfTrades;
   return(lots);
   } 
   


//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
int CheckForOpen(int type){
   bool notrade;  
   if(AccountFreeMargin()<1200*Lots)  return(0);
   if(OrdersTotal()>=3) return(0);
   if(IsTradeContextBusy())return(0);
   int Currency[10];ArrayInitialize(Currency,0);

   for(int c2=0;c2<=OrdersTotal();c2++){
      if (OrderSelect(c2,SELECT_BY_POS)==true){
         if(OrderType()==OP_BUY){
            if (OrderSymbol()== "GBPJPY") 
               {Currency[2]=Currency[2]+1;Currency[8]=Currency[8]-1;continue;}
             if (OrderSymbol()== "EURAUD")
               {Currency[1]=Currency[1]+1;Currency[3]=Currency[3]-1;continue;}
            if (OrderSymbol()== "EURUSD")
               {Currency[1]=Currency[1]+1;Currency[5]=Currency[5]-1;continue;}
            if (OrderSymbol()== "EURGBP") 
               {Currency[1]=Currency[1]+1;Currency[2]=Currency[2]-1;continue;}
            if (OrderSymbol()== "EURCHF") 
               {Currency[1]=Currency[1]+1;Currency[6]=Currency[6]-1;continue;}
            if (OrderSymbol()== "EURJPY") 
               {Currency[1]=Currency[1]+1;Currency[8]=Currency[8]-1;continue;}
            if (OrderSymbol()== "GBPUSD") 
               {Currency[2]=Currency[2]+1;Currency[5]=Currency[5]-1;continue;}
           if (OrderSymbol()== "GBPCHF") 
               {Currency[2]=Currency[2]+1;Currency[6]=Currency[6]-1;continue;}
            if (OrderSymbol()== "AUDUSD") 
               {Currency[3]=Currency[3]+1;Currency[5]=Currency[5]-1;continue;}
            if (OrderSymbol()== "USDCHF") 
               {Currency[5]=Currency[5]+1;Currency[6]=Currency[6]-1;continue;}
            if (OrderSymbol()== "USDJPY") 
               {Currency[5]=Currency[5]+1;Currency[8]=Currency[8]-1;continue;}
            if (OrderSymbol()== "USDCAD") 
               {Currency[5]=Currency[5]+1;Currency[7]=Currency[7]-1;continue;}
         }   

         if (OrderType()==OP_SELL) {
            if (OrderSymbol()== "EURAUD")
               {Currency[1]=Currency[1]-1;Currency[3]=Currency[3]+1;continue;}
            if (OrderSymbol()== "EURUSD") 
               {Currency[1]=Currency[1]-1;Currency[5]=Currency[5]+1;continue;}
            if (OrderSymbol()== "EURGBP") 
               {Currency[1]=Currency[1]-1;Currency[2]=Currency[2]+1;continue;}
            if (OrderSymbol()== "EURCHF") 
               {Currency[1]=Currency[1]-1;Currency[6]=Currency[6]+1;continue;}
            if (OrderSymbol()== "EURJPY") 
               {Currency[1]=Currency[1]-1;Currency[8]=Currency[8]+1;continue;}
            if (OrderSymbol()== "GBPUSD") 
               {Currency[2]=Currency[2]-1;Currency[5]=Currency[5]+1;continue;}
            if (OrderSymbol()== "GBPJPY") 
               {Currency[2]=Currency[2]-1;Currency[8]=Currency[8]+1;continue;}
            if (OrderSymbol()== "GBPCHF") 
               {Currency[2]=Currency[2]-1;Currency[6]=Currency[6]+1;continue;}
            if (OrderSymbol()== "AUDUSD") 
               {Currency[3]=Currency[3]-1;Currency[5]=Currency[5]+1;continue;}
            if (OrderSymbol()== "USDCHF") 
               {Currency[5]=Currency[5]-1;Currency[6]=Currency[6]+1;continue;}
            if (OrderSymbol()== "USDJPY") 
               {Currency[5]=Currency[5]-1;Currency[8]=Currency[8]+1;continue;}
            if (OrderSymbol()== "USDCAD") 
               {Currency[5]=Currency[5]-1;Currency[7]=Currency[7]+1;continue;}
         }
      }
   }
   for(int c1=0;c1<NumberOfPairs;c1++){
      notrade=false;
      for(c2=0;c2<=OrdersTotal();c2++){
         if (OrderSelect(c2,SELECT_BY_POS)==true){
            if(OrderSymbol()==CurrencyPair[c1][2])notrade=true;
         }
      }

      if(CurrencyPair[c1][1]=="Long"){
         if(CurrencyPair[c1][2]=="GBPJPY")
            if(Currency[2]>=MaxPerDirection || Currency[8]<=-1*MaxPerDirection)
               {notrade=true;continue;}
          if(CurrencyPair[c1][2]=="EURUSD")
            if(Currency[1]>=MaxPerDirection || Currency[5]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="EURCHF")
            if(Currency[1]>=MaxPerDirection || Currency[6]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="EURGBP")
            if(Currency[1]>=MaxPerDirection || Currency[2]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="EURJPY")
            if(Currency[1]>=MaxPerDirection || Currency[8]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="EURAUD")
            if(Currency[1]>=MaxPerDirection || Currency[3]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="GBPUSD")
            if(Currency[2]>=MaxPerDirection || Currency[5]<=-1*MaxPerDirection)
               {notrade=true;continue;}
        if(CurrencyPair[c1][2]=="GBPCHF")
            if(Currency[2]>=MaxPerDirection || Currency[6]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="AUDUSD")
            if(Currency[3]>=MaxPerDirection || Currency[5]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="USDJPY")
            if(Currency[5]>=MaxPerDirection || Currency[8]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="USDCHF")
            if(Currency[5]>=MaxPerDirection || Currency[6]<=-1*MaxPerDirection)
               {notrade=true;continue;}
         if(CurrencyPair[c1][2]=="USDCAD")
            if(Currency[5]>=MaxPerDirection || Currency[7]<=-1*MaxPerDirection)
               {notrade=true;continue;}
      }

      if (CurrencyPair[c1][1]=="Short"){
         if(CurrencyPair[c1][2]=="EURUSD")
            if(Currency[5]>=MaxPerDirection || Currency[1]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="EURCHF")
            if(Currency[6]>=MaxPerDirection || Currency[1]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="EURGBP")
            if(Currency[2]>=MaxPerDirection || Currency[1]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="EURJPY")
            if(Currency[8]>=MaxPerDirection || Currency[1]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="EURAUD")
            if(Currency[3]>=MaxPerDirection || Currency[1]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="GBPUSD")
            if(Currency[5]>=MaxPerDirection || Currency[2]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="GBPJPY")
            if(Currency[8]>=MaxPerDirection || Currency[2]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="GBPCHF")
            if(Currency[6]>=MaxPerDirection || Currency[2]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="AUDUSD")
            if(Currency[5]>=MaxPerDirection || Currency[3]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="USDJPY")
            if(Currency[8]>=MaxPerDirection || Currency[5]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="USDCHF")
            if(Currency[6]>=MaxPerDirection || Currency[5]<=-1*MaxPerDirection)
               {notrade=true;}
         if(CurrencyPair[c1][2]=="USDCAD")
            if(Currency[7]>=MaxPerDirection || Currency[5]<=-1*MaxPerDirection)
               {notrade=true;}
      }     
       
       if (notrade==false){
         MacUp=false; 
         MacDown=false; 
         Mac(CurrencyPair[c1][2]);
         double l=0.1*MathRound(10*Lots/Base(CurrencyPair[c1][2]));   
         if (l<0.1) l=0.1;
         if (l>5) l=5;
         string pair=CurrencyPair[c1][2];
         if ( AccountFreeMargin()<1200*l) return(0);
         if (CurrencyPair[c1][1]=="Long")
            if (MacUp)            
              {int ticket10=OrderSend(pair,OP_BUY,l,MarketInfo(pair,MODE_ASK),2,MarketInfo(pair,MODE_ASK)-Multiplier*TakeProfit(pair)*MarketInfo(pair,MODE_POINT),MarketInfo(pair,MODE_ASK)+TakeProfit(pair)*MarketInfo(pair,MODE_POINT),Name,MagicExpert,0,Blue);
               return(0);}      
         if (CurrencyPair[c1][1]=="Short")
            if (MacDown)            
              {int ticket20=OrderSend(pair,OP_SELL,l,MarketInfo(pair,MODE_BID),2,MarketInfo(pair,MODE_BID)+Multiplier*TakeProfit(pair)*MarketInfo(pair,MODE_POINT),MarketInfo(pair,MODE_BID)-TakeProfit(pair)*MarketInfo(pair,MODE_POINT),Name,MagicExpert,0,Blue);
               return(0);}      
       }
   }//next c1    

}//end check for open 


//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
int CheckForClose(int type){
 
    
if (Duration!=0){ //Lenght of time a postion is held 
  for(int i2=OrdersTotal();i2>=0;i2--) {
  if(OrderSelect(i2,SELECT_BY_POS,MODE_TRADES)==false)        continue;
  if(OrderMagicNumber()!=MagicExpert) continue; 
      if (OrderOpenTime()<CurTime()-Duration*60*1440){OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Yellow);return(0);} }
  }   //end duration check
    
    
    
  }//end check for close 

//======================Start function=======================


                                   

int start()
  {

//---- check for history and trading   
   if (DayOfYear()!=LastRan)RunOnceDaily(DayOfYear());
   if(Bars<100 || IsTradeAllowed()==false) return(0);
   if (AccountBalance()<2000) return(0);
//----  open orders by current symbol
         if (OrdersTotal()<MaxNumberOfTrades) 
               CheckForOpen(1);

//----
  }//end of start function
  
//+------------------------------------------------------------------+


 
 

Profitability Reports

NZD/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%

Comments