It returns an enumeration. You never need to know the value. Don't use 60 or 16385; use the proper enumeration (PERIOD_H1).
please... when I use Period() on h1 on mt5 why is the value different and not the same as mt4... on mt4 period_h1 is 60 while on mt5 it is 16385... please help
The difference in the values returned by Period() function between MetaTrader 4 (MT4) and MetaTrader 5 (MT5) is due to how each platform assigns numerical values to different timeframes.
In MT4:
The value returned for the H1 timeframe by Period() function is indeed 60.
In MT5:
The value returned for the H1 timeframe by Period() function is 16385.
This discrepancy occurs because MT5 uses a different numerical representation for timeframes compared to MT4. While the actual timeframe remains the same (H1 in both cases), the numerical values assigned to timeframes differ between the two platforms.
To adapt your scripts or expert advisors to work seamlessly across both MT4 and MT5 platforms, you can create conditional statements that account for the differences in timeframe values. Here is an example i made for you:
// Check if the current platform is MT4 #ifdef __MQL4__ int periodH1 = 60; #else int periodH1 = 16385; #endif
So, by using conditional compilation directives like #ifdef __MQL4__ , you can differentiate between MT4 and MT5 environments and assign the appropriate values accordingly.
This way, your scripts or expert advisors can handle timeframe-related calculations consistently across both MetaTrader platforms.
Conversely, i would recommend you using the proper way by using the Enum Period_H1, or Period_D1 etc. Whichever period you are using

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use