I am looking for a MQL5 script calculating the performance of a product over X days.

 

Hello,

I am looking for a MQL5 script calculating the performance of a product over X days.

I coded that, it must be improvable.
In particular how to remove the zeros after the 2 digits after the decimal point?

//+------------------------------------------------------------------+
//|                                                stPerformance.mq5 |
//|                                   Copyright 2019, Pierre Rougier |
//|                           https://www.mql5.com/en/users/pierre8r |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Pierre Rougier"
#property link      "https://www.mql5.com/en/users/pierre8r"
#property version   "1.00"

input int  numberOfDays=10;

double performance;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   performance=((iClose(_Symbol,PERIOD_D1,0)-iOpen(_Symbol,PERIOD_D1,numberOfDays))/iOpen(_Symbol,PERIOD_D1,numberOfDays))*100;
   Print("The performance of "+_Symbol+" for the last "+IntegerToString(numberOfDays)+" days is "+DoubleToString(NormalizeDouble(performance,2)));
   Alert("The performance of "+_Symbol+" for the last "+IntegerToString(numberOfDays)+" days is "+DoubleToString(NormalizeDouble(performance,2)));
  }
//+------------------------------------------------------------------+



Regards,
Pierre

 
I coded that, it must be improvable.
In particular how to remove the zeros after the 2 digits after the decimal point?
 

Hello Pierre the digits are specified in the DoubleToString function as the second parameter.

Alert("The performance of "+_Symbol+" for the last "+IntegerToString(numberOfDays)+" days is "+DoubleToString(NormalizeDouble(performance,2),2));
 

Also:

Alert(StringFormat("The performance of %s for the last %d days is %.2f", symbol, numberOfDays, performance));
 
Reason: