| //+------------------------------------------------------------------+
|
| //| ModalityCalendar.mqh |
|
| //| AnimateDread |
|
| //| |
|
| //| WHEN IT IS. Day of week, hour, day of month and days to month end |
|
| //| of the signal bar (broker time, the same clock the bars carry). |
|
| //| Turn-of-month and weekday effects are the calendar edges equity |
|
| //| indices are known for; recorded so the journal can say whether |
|
| //| this book's dips behave differently on them. |
|
| //+------------------------------------------------------------------+
|
| #ifndef WARRIOR_MODALITYCALENDAR_MQH
|
| #define WARRIOR_MODALITYCALENDAR_MQH
|
|
|
| #include "Modality.mqh"
|
|
|
| class CModalityCalendar : public CModality
|
| {
|
| public:
|
| virtual string Name(void) const override { return "calendar"; }
|
| virtual bool Read(const SBarRef &bar, SMarketContext &ctx) override
|
| {
|
| MqlDateTime t;
|
| TimeToStruct(bar.time, t);
|
| //--- Days to month end from the calendar itself, so leap years need no table.
|
| MqlDateTime today = t, next = t;
|
| today.hour = today.min = today.sec = 0;
|
| next.hour = next.min = next.sec = 0;
|
| next.day = 1;
|
| if(++next.mon > 12)
|
| {
|
| next.mon = 1;
|
| next.year++;
|
| }
|
| ctx.v[CTX_DOW] = t.day_of_week;
|
| ctx.v[CTX_HOUR] = t.hour;
|
| ctx.v[CTX_DOM] = t.day;
|
| ctx.v[CTX_TO_MONTH_END] = (double)((StructToTime(next) - StructToTime(today)) / 86400) - 1.0;
|
| return true;
|
| }
|
| };
|
| #endif // WARRIOR_MODALITYCALENDAR_MQH
|