Download MetaTrader 5

How to Set TimeCurrent() as default time

To add comments, please log in or register
macpee
488
macpee  

Hello, comrades. How can I set the current time as default time to appear in the property window for a variable I created to handle time in the property window, without having to enter the current time in the editor each time I want to invoke the property window? Thank you in advance.

Please see code below:

extern string CurrentTime = "2016.04.17 16:00"; 
  
//This default value was entered manually, 
//and will be in the past by the time the
// property window is open during run


An idea struck my mind to to do the following:

extern string CurrentTime = TimeToString(TimeCurrent()); 

If this works, it should give me what I want. However, I have not executed it yet as the market is closed as of now (weekend).

Your suggestions will be highly appreciated.

You might be wondering why I want the current time in the property window. Well, to clarify such wonder, I have another variable called EnterTime, to enter a future time. The idea is to copy the current time from the CurrentTime variable and paste in the EnterTime variable. By so doing, we will only have to edit the minute and/or hour, and not the entire date. Unlike the chart, it is possible to copy values from the property window.

Fernando Carreiro
2246
Fernando Carreiro  
As far as I know "extern", "input" and "sinput" variables/properties can only be assigned constants and don't accept dynamic data (such as functions).
Carl Schreiber
6777
Carl Schreiber  
FMIC:
As far as I know "extern", "input" and "sinput" variables/properties can only be assigned constants and don't accept dynamic data (such as functions).
"extern" variables can be changed within an ea, indi, but "input" vars. can't.
Fernando Carreiro
2246
Fernando Carreiro  
gooly:
"extern" variables can be changed within an ea, indi, but "input" vars. can't.

The discussion is about initial assignment, as macpee wants to set the default value presented to the user when the EA/Indicator is attached to a chart and the properties can be set by the user

He is NOT talking about changing the value after the fact!

whroeder1
15015
whroeder1  
macpeeThe idea is to copy the current time from the CurrentTime variable and paste in the EnterTime variable. By so doing, we will only have to edit the minute and/or hour, and not the entire date
  1. Can not be done.
  2. Best you can do is make the variable a string "00:00", have them edit it, and then convert it to current date plus entered time.
macpee
488
macpee  
Thank you @EMIC, you got my point. The idea is more like presenting the initial assignment to the user by the EA via the properties window for copying purposes, and not to input the value by the user for use by the EA.
macpee
488
macpee  
WHRoeder:
macpeeThe idea is to copy the current time from the CurrentTime variable andpaste in the EnterTime variable. By so doing, we will only have to editthe minute and/or hour, and not the entire date
  1. Can not be done.
  2. Best you can do is make the variable a string "00:00", have them edit it, and then convert it to current date plus entered time.

@WHRoeder, I think you got the idea. Moreover, you have proffered a solution to the issue. As a matter of fact the additional task of having to copy and paste dates from one property to the other in the property window is eliminated by your solution. However, suppose an eco data is to be released at 24:05, and the current time is 23:58. But you have to be quick in setting the time for the EA to take action during the 24:05. Also, you know the two times are in two different days. It means that you will have set a time in the past (elapsed by 24 hours) during the eco data time.
To add comments, please log in or register