Current Month Name mql5 - page 2

 

We already helped you providing the code you wanted for retreiving Month name based on month number...

But we can't implement the whole code for you. There is the Freelance section for this kind of requests.

Seems you don't know how to use ObjectSetString command, this can help you. 

https://www.mql5.com/en/docs/objects/objectsetstring

Documentation on MQL5: Object Functions / ObjectSetString
Documentation on MQL5: Object Functions / ObjectSetString
  • www.mql5.com
The function sets the value of the corresponding object property. The object property must be of the string type. There are 2 variants of the...
 
Fabio Cavalloni #:

We already helped you providing the code you wanted for retreiving Month name based on month number...

But we can't implement the whole code for you. There is the Freelance section for this kind of requests.

Seems you don't know how to use ObjectSetString command, this can help you. 

https://www.mql5.com/en/docs/objects/objectsetstring

thank you, that's enough for me, exactly, I didn't know it existed, I didn't want the whole code, just to show how to display the current month text label
 
Fabio Cavalloni #:

We already helped you providing the code you wanted for retreiving Month name based on month number...

But we can't implement the whole code for you. There is the Freelance section for this kind of requests.

Seems you don't know how to use ObjectSetString command, this can help you. 

https://www.mql5.com/en/docs/objects/objectsetstring

ObjectSetString(0,"Month",OBJPROP_TEXT,  "Month Profit / Loss" +DoubleToString(dayprofywm,2)+"  "+AccountInfoString(ACCOUNT_CURRENCY)" "+ );

correction, I know what ObjectSetString is, but I don't know how to add + current month text  to the end
 

Problem solved, in case it's useful to someone in the future


   long time_now =TimeCurrent();
   MqlDateTime time;
   TimeToStruct(time_now, time);
   uint month= time.mon;

 
Zbynek Liska #:

Problem solved, in case it's useful to someone in the future


Which problem have you solved, as that code simply provides the number of the month, it doesn't solve your first question of how to make it a text representation of the month, nor the second of how to add the text value to the label ?

 
Paul Anscombe #:

Which problem have you solved, as that code simply provides the number of the month, it doesn't solve your first question of how to make it a text representation of the month, nor the second of how to add the text value to the label ?

Of course, a programmer would do it better, but it's enough for me if it works
    if (month == 4) 
   
   {
   
 
   ObjectSetString(0,"Month",OBJPROP_TEXT,  "April : Profit / Loss  " +DoubleToString(dayprofywm,2)+"  "+AccountInfoString(ACCOUNT_CURRENCY));

   
   }


 
Zbynek Liska #:

Of course, a programmer would do it better, but it's enough for me if it works


assuming you set an int value for the month to the variable month, use this function so you only need to code ObjectSetString once

ObjectSetString(0,"Month",OBJPROP_TEXT,  TextMonth(month) + " : Profit / Loss  " +DoubleToString(dayprofywm,2)+"  "+AccountInfoString(ACCOUNT_CURRENCY));


string TextMonth(int month)
{
   switch(month)
   {
      case 1: return "January";
      case 2: return "February";
      case 3: return "March";
      case 4: return "April";
      case 5: return "May";
      case 6: return "June";
      case 7: return "July";
      case 8: return "August";
      case 9: return "September";
      case 10: return "October";
      case 11: return "November";
      case 12: return "December";
      default: return "Month Error";
   }
   return "Month Error";
}
      
 
Paul Anscombe #:

assuming you are assigning an int value for the month to the variable month, then use this function so that you only need to code the ObjectSetString once.

perfect, thank you very much, of course I would never have come up with your solution in my life