Martian4x:
I'm trying to add 1 and 2 months to date, but all solutions I find online are about MQL4, which doesn't work on MQL5 compiler. Can anyone suggest an MQL5 way of adding months or days to a date?
Thank you.
This wont work: newTime = time + PeriodSeconds(PERIOD_MN1) ?
I'm trying to add 1 and 2 months to date, but all solutions I find online are about MQL4, which doesn't work on MQL5 compiler. Can anyone suggest an MQL5 way of adding months or days to a date?
Thank you.
Martian4x #: Can you please provide an example code on how to perform addition? Newbie here.
You should first learn how to code in the MQL Object Oriented Programming (OOP) style. By that I mean, how to code with classes and objects. Once you know that, you will not need an example.
The MQL documentation about OOP is not very "user friendly" in my opinion, so search the web for tutorials on C++ OOP which is on what MQL OOP is based on.

Documentation on MQL5: Language Basics / Object-Oriented Programming
- www.mql5.com
Object-Oriented Programming - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Well I figured it out. For anyone stuck here's what I did.
code:
Declaration
#include <Tools\DateTime.mqh>
#include <Tools\DateTime.mqh>
struct CDateTime;
datetime StartDate, EndDate;
code:
CDateTime newDate;
TimeToStruct(StartDate,newDate);
newDate.MonInc(1);
EndDate = newDate.DateTime();

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thank you.