Hello Expert Coders,
Above mql5 code for specifying trading times in "hour:min" isn't working, the EA generates only zero values in backtesting.
I hope it's a minor coding error, and would appreciate your expert input.
Thanks in advance for your kind assistance.
M.
//+------------------------------------------------------------------+ //| InTradingTime.mq5 | //| Copyright 2021, Rosh Jardine Capital | //| https://roshjardine.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, Rosh Jardine Capital" #property link "https://roshjardine.com" #property version "1.00" #property script_show_inputs //--- input parameters input int InpStartHour = 0; input int InpStartMinute = 59; input int InpEndHour = 23; input int InpEndMinute = 58; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- InTradingTime(); } //+------------------------------------------------------------------+ bool InTradingTime() { datetime Now = TimeCurrent(); MqlDateTime NowStruct; TimeToStruct(Now,NowStruct); int StartTradingSeconds = (InpStartHour*3600) + (InpStartMinute*60); int EndTradingSeconds = (InpEndHour*3600) + (InpEndMinute*60); int runningseconds = (NowStruct.hour*3600) + (NowStruct.min*60); ZeroMemory(NowStruct); if ((runningseconds>StartTradingSeconds)&&(runningseconds<EndTradingSeconds)) { Print("within trading time"); return(true); } Print("outside of trading time"); return(false); }
Thanks @roshjardine for instant reply with code in detail.
My ea script doesn't have void OnStart() type function, instead have void OnTick() and ends with return;} operator.
I tried inserting InTradingTime(); before and after return; of OnTick(), without retun; operator and also at int OnInit(), but none worked. I still get same issue of zero values in backtesting. And if I were to use void OnStart() code as it is for InTradtingTime(); then I get a lot of errors!
Do you know the correct place to insert InTradingTime(); function?
Thanks again and regards,
M.
Hi Sardion,
It's sorted, just had to place within void OnEveryTick(), bit of other code re-arrangement and it woked perfectly.
Thanks again for your code and file.
Regards,
M.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello Expert Coders,
Above mql5 code for specifying trading times in "hour:min" isn't working, the EA generates only zero values in backtesting.
I hope it's a minor coding error, and would appreciate your expert input.
Thanks in advance for your kind assistance.
M.