EA31337 / EA31337-classes

📦📈 EA31337 framework (MQL library for writing trading Expert Advisors, indicators and scripts)
https://ea31337.github.io/EA31337-classes
GNU General Public License v3.0
186 stars 98 forks source link

Write DateTime class which implements Date and Time functions. #2

Closed kenorb closed 8 years ago

kenorb commented 8 years ago

Convert existing code (DateTime.mqh) into class which implements all listed Date and Time methods using the same name as in MT4 documentation (some of them are already there). These methods should work for both MQL4 (MT4) and MQL5 (MT5) platforms. Remove anything else which is not related to Date and Time.

E.g. Hour() method should return Hour() value in MT4, but MqlDateTime in MT5.

Language: MQL 4&5

To compile for each version, you need to install both platforms (MT4 & MT5) and compile using MetaEditor.

LemonBoy commented 8 years ago

Something like [1] ? It provides some glue for MQL5's missing functions, I did test it with a simple script and it works just fine and moth MQL{4,5} found no syntax errors.

[1] https://ptpb.pw/IF5x

kenorb commented 8 years ago

@LemonBoy Sorry for a late reply. Yes, however I expect those methods wrapped in the class, so I could call the methods consistently from the other file without having worrying about #ifdef outside of the class or in which version the main MQL file is compiled. In other words I just want to call DateTime::Day() (or by class instance) from both MQL4/MQL5 file and I expect the same result.

For example the code structure should be:

class DateTime {

  int Day() {
    #ifdef __MQL5__
      MqlDateTime dt;
      TimeCurrent(dt);
      return(dt.day);
    #else
      return Day();
    #endif
  }

  // ... more methods
}

where the methods are replication of MQL4 functions and at the same time they're compatible with MQL5 as well. In DateTime class just use only the function related to date time (so the rest non-relevant part can be removed). This is just initial idea, once the format would be consistent, I'll later provide more classes to write, related to specific functions.

LemonBoy commented 8 years ago

So, something like this [1] ?

[1] https://ptpb.pw/jaGL

kenorb commented 8 years ago

That's correct. I think making indentation for #ifdef would look better if it's aligned with the code (the code would be more readable). Check for other missing date related functions as well. If there is any blocker function that can't be ported easily, add @todo for MQL5 so you may ignore.

LemonBoy commented 8 years ago

TimeTradeServer has been added in MQL5 and has no equivalent for MQL4, I'll shift the # tokens once I submit a PR. The other options I didn't bring into the class are the ones that are available for both the versions and making a wrapper sounds quite pointless, no ?

kenorb commented 8 years ago

If TimeTradeServer not there in MQL4, you can still define the method, then return the value for MQL5 but NULL for MQL4 with some code comment (todo), probably this won't be used anyway.

kenorb commented 8 years ago

Looks fine. I'll test it later on. Thanks.