Conversion from String To Number
Hi Guys can anyone help me get past the error "implicit conversion from string to number" when i compile the attached code. reference is line5 trading is allowed, and the function check trading time.
input string StartTradingTime ="00.11";
input string StopTradingTime ="23.10";
string CurrentTime;
bool TradingIsAllowed ="";
//-------------------------------------------------------------------
void OnTick()
{
datetime time=TimeGMT();
CurrentTime=TimeToString (time,TIME_MINUTES);
Comment
( "Trading Is Allowed = ", TradingIsAllowed, "\n",
"Current Time = ", CurrentTime, "\n",
"Start Trading Time = ", StartTradingTime, "\n",
"Stop Trading Time = ", StopTradingTime, "\n"
);
}
//-------------------------------------------------------------------
bool CheckTradingTime()
{
if (StringSubstr (CurrentTime,0,5) >=StartTradingTime)
TradingIsAllowed=true;
if (StringSubstr (CurrentTime,0,5) >=StopTradingTime)
TradingIsAllowed=false;
return TradingIsAllowed;
}
//------------------------------------------------------------------
Use IntegerToString
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.
See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)
Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)Can not be optimized.
Invalid time, format is HH:MMinput string StartTradingTime ="00.11"; input string StopTradingTime ="23.10"; bool CheckTradingTime() { if (StringSubstr (CurrentTime,0,5) >=StartTradingTime) TradingIsAllowed=true; if (StringSubstr (CurrentTime,0,5) >=StopTradingTime) TradingIsAllowed=false; return TradingIsAllowed; }
Optimizable. input int StartTradingTime = 11*60; // "00:11:00" input int StopTradingTime = 23*3600+10*60; // "23:10:00"; bool CheckTradingTime(){ int now = time(); return StartTradingTime <= now && now < StopTradingTime; }
-
Neither versions (above) handle Start=20:00 end=10:00
Awesome Thanks
-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor -
When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.
See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)
Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)Can not be optimized.
Invalid time, format is HH:MMOptimizable. -
Neither versions (above) handle Start=20:00 end=10:00
Hi Guys can anyone help me get past the error "implicit conversion from string to number" when i compile the attached code. reference is line5 trading is allowed, and the function check trading time.