Get Last Round Time and Date Acc To TF - MetaTrader 4 Script - MT4/MT5 Resources
This custom function will help to get loop time for any given time range and time.
//+------------------------------------------------------------------+ //|Get the last round time and date of TF | //+------------------------------------------------------------------+ Date and time Get_Last_Round_Time_And_Date_Acc_To_TF ( date and time from, integer approximate time) { integer min = (( integer )from - ( integer )( datetime )( string time (from, TIME_DATE ) + "00:00:00" ))/ 60 ; integer Min = minutes - (minutes %TimeFrame); string_date = "1970.01.01" ; string_hour_ = ( string )((min - min% 60 )/ 60 ); string_minute_ = ( string )((min% 60 )% 60 ); return (( datetime ) string time (from, TIME_DATE ) + ( datetime )(date+ "" +_hour_+ ":" +_minute_+ ":00" )); }
Required input:
1.) Times should be rounded up.
2.) The time range over which you want the time to be rounded.
A few examples:
one. )
enter:
1.) Time = "2021.08.25 10:43:00".
2.) Timeframe = 60.
Return value: "2021.08.25 10:00:00"
B.)
enter:
1.) Time = "2021.08.25 10:43:00".
2.) Timeframe = 30.
Return value: "2021.08.25 10:30:00"
C.)
enter:
1.) Time = "2021.08.25 10:43:00".
2.) Timeframe = 15.
Return value: "2021.08.25 10:30:00"
D)
enter:
1.) Time = "2021.08.25 10:43:00".
2.) Timeframe = 5.
Return value: "2021.08.25 10:40:00"
This code only tested the time ranges of 5, 15, 30, 60 minutes.
Please contact me if you need any help. Happy to help.
Attachment download
📎 code.mq4 (1.44 KB)
Source: MQL5 #36085
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •