displaying total trade count and total profit within a running EA

 

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? 

 
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 ?
 

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.
 

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 

 
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.

Reason: