Download MetaTrader 5
To add comments, please log in or register
Have you developed a trading robot? Publish it in the Market and make profit!
jazzpur2k
10
jazzpur2k 2016.06.15 03:30 

im having trouble finding the functions that allows me to report number of trades and profit the way i have these other varibles displaying

 

   Comment(StringConcatenate("\nCopyright © 2015, Jasper\nViolentPips EA v1.0 is running.",
                              "\nMomentum delta : ",c,
                              "\niOpen Days Back : ",DaysBack,
                            
                              
                              "\nBasisStepper: ",BasisStepper,
                          
                              "\nLimitedUpPercent: ",LimitedUpPercent,
                              "\nLimitedDownPercent: ",LimitedDownPercent
                            
                             )
           );
 

 i now want my comment to include total trades(only for this EA on this currency within this timeframe)

and also want it to show my accumulating profit  (only for this EA on this currency within this timeframe)

 

im sure this is simple, but every attempt i make, the varibles arnt changing 

 

does anyone have an example program with this feature? 

Alain Verleyen
Moderator
28605
Alain Verleyen 2016.06.15 09:49  
jazzpur2k:

im having trouble finding the functions that allows me to report number of trades and profit the way i have these other varibles displaying

 

 i now want my comment to include total trades(only for this EA on this currency within this timeframe)

and also want it to show my accumulating profit  (only for this EA on this currency within this timeframe)

 

im sure this is simple, but every attempt i make, the varibles arnt changing 

 

does anyone have an example program with this feature? 

There is no such built-in functions, you need to code it. What have you tried ?
whroeder1
13619
whroeder1 2016.06.15 16:43  

jazzpur2k:

i now want my comment to include total trades(only for this EA on this currency within this timeframe)

and also want it to show my accumulating profit  (only for this EA on this currency within this timeframe)

Show us your OrderSelect loop where you count trades and sum profit.
jazzpur2k
10
jazzpur2k 2016.06.16 12:41  

i started working with mt4 with only a half year of programming knowledge from highschool over ten years ago.

 

this may be beyond me then. i cant code from scratch yet. im more or less, breaking down several other examples to see how things function

and then editing them to get what i want and referencing the mql4 dictionary 

 

i figured this would be a worthy feature and many would throw it in their programs to illustrate progress.

 

Backtesting displays all of this in the report tab, i figured these would be built-in

 

summing profits....i wouldnt even know where to start...

 

as for reporting trade count ive been trying to report OrdersTotal()

   for(cnt=0;cnt<OrdersTotal();cnt++)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL &&
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber) total++;
   }
   return(total);
}

 

 

i guess i wrongly assumed everyone would want this feature in their EA so i thought there be a plethora of examples to illustrate 

Janek6191
29
Janek6191 2016.06.18 06:15  
double ProfitAll(){
   int err=0;
   double profit=0;
   
   for(int i=OrdersTotal()-1; i >= 0; i--){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
            if(OrderMagicNumber()== magic)
                profit+=OrderProfit()+OrderCommission();
      }
      else
      {
         Print("Failed to Select Order.");
         err = GetLastError();
         Print("Encountered an error while seleting order ,error number "+(string)err+" "+ErrorDescription(err));
      }
   }
   return profit;
}

int totalOpenOrders(){
  int total=0;
  int type;
  for(int i=OrdersTotal()-1; i >= 0; i--){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(OrderMagicNumber()== magic){
            type=OrderType();
            if(type == OP_BUY || type == OP_SELL)
               total++;
         }
      }
           else Print("Failed to select order",GetLastError());
  }
  return total;
}

For this to work you would probably have to make your magic number dependent on your chart symbol and timeframe.

For example something like this:

int generateMagic(){
   string mySymbol=StringSubstr(_Symbol,0,6);
   int pairNumber=0;
   int GeneratedNumber=0;
        if(mySymbol == "AUDCAD")    pairNumber=1;
   else if(mySymbol == "AUDCHF")    pairNumber=2;
   else if(mySymbol == "AUDJPY")    pairNumber=3;
   else if(mySymbol == "AUDNZD")    pairNumber=4;
   else if(mySymbol == "AUDUSD")    pairNumber=5;
   else if(mySymbol == "EURAUD")    pairNumber=9;
   else if(mySymbol == "EURCAD")    pairNumber=10;
   else if(mySymbol == "EURCHF")    pairNumber=11;
   else if(mySymbol == "EURUSD")    pairNumber=15;
   else if(mySymbol == "GBPAUD")    pairNumber=16;
   else if(mySymbol == "GBPCAD")    pairNumber=17;
   else if(mySymbol == "GBPCHF")    pairNumber=18;
   else if(mySymbol == "GBPJPY")    pairNumber=19;
   else if(mySymbol == "USDJPY")    pairNumber=28;
   else                             pairNumber=29;
   
   GeneratedNumber=MagicSeed+(pairNumber*100)*Period();
   return(GeneratedNumber);
  }

  Just add the pairs you want to trade. (and their correct name for your broker)

  This method might not be bulletproof but it works for me.

/
To add comments, please log in or register