Skip to content

Commit

Permalink
Market: MarketTimeForex inherits from DateTimeEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Sep 15, 2021
1 parent ac5b5d6 commit 76db93e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DateTime.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DateTime {
DateTime() { TimeToStruct(TimeCurrent(), dt_curr); }
DateTime(DateTimeEntry &_dt) { dt_curr = _dt; }
DateTime(MqlDateTime &_dt) { dt_curr = _dt; }
DateTime(datetime _dt) { dt_curr.SetDateTime(_dt); }
DateTime(datetime _dt) { dt_curr.Set(_dt); }

/**
* Class deconstructor.
Expand Down Expand Up @@ -199,7 +199,7 @@ class DateTime {
/**
* Updates datetime to the current one.
*/
void Update() { dt_curr.SetDateTime(TimeCurrent()); }
void Update() { dt_curr.Set(TimeCurrent()); }

/* Conditions */

Expand Down
28 changes: 22 additions & 6 deletions DateTime.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct DateTimeStatic;

// Includes.
#include "DateTime.enum.h"
#include "Std.h"

#ifndef __MQLBUILD__
/**
Expand Down Expand Up @@ -229,11 +230,10 @@ struct DateTimeStatic {
struct DateTimeEntry : MqlDateTime {
int week_of_year;
// Struct constructors.
DateTimeEntry() { SetDateTime(); }
DateTimeEntry(datetime _dt) { SetDateTime(_dt); }
DateTimeEntry() { Set(); }
DateTimeEntry(datetime _dt) { Set(_dt); }
DateTimeEntry(MqlDateTime& _dt) {
// @fixit Should also set day of week.
((MqlDateTime)THIS_REF) = _dt;
Set(_dt);
#ifndef __MQL__
throw NotImplementedException();
#endif
Expand Down Expand Up @@ -286,8 +286,24 @@ struct DateTimeEntry : MqlDateTime {
int GetYear() { return year; }
datetime GetTimestamp() { return StructToTime(THIS_REF); }
// Setters.
void SetDateTime() { TimeToStruct(TimeCurrent(), THIS_REF); }
void SetDateTime(datetime _dt) { TimeToStruct(_dt, THIS_REF); }
void Set() {
TimeToStruct(::TimeCurrent(), THIS_REF);
// @fixit Should also set day of week.
}
void SetGMT() {
TimeToStruct(::TimeGMT(), THIS_REF);
// @fixit Should also set day of week.
}
// Set date and time.
void Set(datetime _time) {
TimeToStruct(_time, THIS_REF);
// @fixit Should also set day of week.
}
// Set date and time.
void Set(MqlDateTime& _time) {
THIS_REF = _time;
// @fixit Should also set day of week.
}
void SetDayOfMonth(int _value) {
day = _value;
day_of_week = DateTimeStatic::DayOfWeek(); // Zero-based day of week.
Expand Down
8 changes: 5 additions & 3 deletions Market.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
*/

// Includes.
#include "DateTime.struct.h"
#include "Std.h"

// Structure for trade time static methods.
struct MarketTimeForex : MqlDateTime {
struct MarketTimeForex : DateTimeEntry {
// Market sessions for trading Forex.
enum ENUM_MARKET_TIME_FOREX_HOURS {
MARKET_TIME_FOREX_HOURS_NONE = 0 << 0,
Expand All @@ -49,8 +50,9 @@ struct MarketTimeForex : MqlDateTime {
MARKET_TIME_FOREX_HOURS_PACIFIC = MARKET_TIME_FOREX_HOURS_SYDNEY | MARKET_TIME_FOREX_HOURS_WELLINGTON,
};
// Constructors.
MarketTimeForex(datetime _time_gmt) { TimeToStruct(_time_gmt, THIS_REF); }
MarketTimeForex(MqlDateTime &_dt_gmt) { THIS_REF = _dt_gmt; }
MarketTimeForex() { Set(::TimeGMT()); }
MarketTimeForex(datetime _time_gmt) { Set(_time_gmt); }
MarketTimeForex(MqlDateTime &_dt_gmt) { Set(_dt_gmt); }
// State methods.
/* Getters */
bool CheckHours(unsigned int _hours_enums) {
Expand Down

0 comments on commit 76db93e

Please sign in to comment.