
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
As already said by forex2start, you CAN NOT return a value in OnTick() event handler which is defined with void. Use this :
Anyway, I doubt this condition with strings will give you the expected result.
My timer probably isn't very nice but I use a boolean.
So if the current time is between the two times I want it to run (e.g. 6am and 5pm), then set the boolean to true.
bool time;
int startTime = 6;
int endTime = 17;
void OnTick()
{
datetime tm=TimeCurrent(); //gets current time in datetime data type
string str=TimeToString(tm,TIME_MINUTES); //changing the data type to a string
string current = StringSubstr(str, 0, 2); //selecting the first two characters of the datetime e.g. if it's 5:00:00 then it'll save it as 5, if it's 18 it will save 18.
int currentTimeInt = StringToInteger(current); //changes the string to an integer
if(currentTimeInt>startTime && endTime>currentTimeInt) {
time = true;
}
else {
time = false;
}
if(time == true) {
//do calculations here
}
}
My timer probably isn't very nice but I use a boolean.
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code properly in a new post.