Hi Everyone,, hope all's well. Been working on moving code from mql4 to mql5 but having a slight issue specifying for when variables are to be reverted back to false at the start of the day.
Here's the mql4 code to revert bool variables CAN_BUY and CAN_SELL back to false,,
Any help will be highly appreciated.If possible to revert variables during first 30 minutes of the day,,,every day. Thanks folks!!
If you use hour to test then assuming this is in OnTick you will be resetting for a whole hour every tick.
Better to check the day or the week or the time of the latest daily bar say and compare against a variable say lastdate if not the same:
set lastdate to the date and set CAN_BUY and CAN_SELL to false no need to check what they are already if your desired outcome is false.
- www.mql5.com
If you use hour to test then assuming this is in OnTick you will be resetting for a whole hour every tick.
Better to check the day or the week or the time of the latest daily bar say and compare against a variable say lastdate if not the same:
set lastdate to the date and set CAN_BUY and CAN_SELL to false no need to check what they are already if your desired outcome is false.
Hey Paul,,, first off thanks,,, appreciated plenty. As the EA sends alerts during the day,,, CAN_BUY and CAN_SELL are altered to true. I need to reset back to false withing the first hour of the day, whether Monday, Wednesday or any trading day for that matter. Then after the 1st hour i await alerts as CAN_BUY and CAN_SELL are then false. Yes, its OnTick,, or how better can i do it??? Thanksagain>
MqlDateTime time; TimeToStruct(TimeCurrent(),time); int Year = time.year; // Year int Month = time.mon; // Month int Day_of_Month = time.day; // Day int Hour = time.hour; // Hour int Minutes = time.min; // Minutes int Seconds = time.sec; // Seconds int Day_of_Week = time.day_of_week; // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) int Day_of_Year = time.day_of_year; // Day number of the year (January 1st is assigned the number value of zero)
Hey Paul,,, first off thanks,,, appreciated plenty. As the EA sends alerts during the day,,, CAN_BUY and CAN_SELL are altered to true. I need to reset back to false withing the first hour of the day, whether Monday, Wednesday or any trading day for that matter. Then after the 1st hour i await alerts as CAN_BUY and CAN_SELL are then false. Yes, its OnTick,, or how better can i do it??? Thanksagain>
You have solution given by Marco if you intend to work with specific hour/Minute etc. Here is your implementation:
if(Hour ==0 && Minutes <=30 ) //First 30 Min of day //--do reset
Another typical way is to check if you are on new day as suggested by Paul. Its good for VPS and you need set lastdate to Global var or save to file to avoid skipping reset. Sample:
bool NewDay() { static datetime last_date = 0; if(last_date <iTime(NULL,PERIOD_D1,0)) { last_date = iTime(NULL,PERIOD_D1,0); return true; } return false; } //+------------------------------------------------------------------+ if(NewDay()) //--do reset
Much appreciated Marco!!!! Thanks!
You have solution given by Marco if you intend to work with specific hour/Minute etc. Here is your implementation:
Another typical way is to check if you are on new day as suggested by Paul. Its good for VPS and you need set lastdate to Global var or save to file to avoid skipping reset. Sample:
Thank you much Langat Naftali!!!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Everyone,, hope all's well. Been working on moving code from mql4 to mql5 but having a slight issue specifying for when variables are to be reverted back to false at the start of the day.
Here's the mql4 code to revert bool variables CAN_BUY and CAN_SELL back to false,,
Any help will be highly appreciated.If possible to revert variables during first 30 minutes of the day,,,every day. Thanks folks!!