Download MetaTrader 5

datetime to string

To add comments, please log in or register


I am, obviously unsuccessfully, trying to paste datetime into string:

datetime dt_EAExpires=D'2016.12.31 23:59';
extern string EA_expires_txt="--- EA expires on: "+TimeToString(dt_EAExpires,TIME_DATE|TIME_MINUTES)+" ---"; /*2016.12.31 23:59 ---";*/ // --- EXPIRATION DATE ---

 This raises an error: '+' - constant expected OmChi EA.mq4 76 101

Adding 'const' before datetime does not solve the issue.

Please advise.


Thank you,

 Best regards,



S love nia 

EDIT: it looks like this will not work - ever, since I am trying to process data before initialization (at compile time?).
Fernando Carreiro
Fernando Carreiro  

You cannot use variable expressions (such as calls to functions) when setting the initial value of an "extern" or "input" variable/parameter. They are presented to the user before execution begins, so they have to be of a constant nature.

You can however, change the value of "extern" parameters within the EA execution, such as in the OnInit() or OnTick(), but you cannot change "input" variables.

To add comments, please log in or register