Eine Lösung die ich selber geschrieben habe und erfolgreich verwende.
Diese Funktion gibt die aktuelle quote/trade session wieder, wenn vorhanden und sucht den Anfang der nächsten Sitzung.
Gibt es keine Sitzung zum aktuellen Zeitpunkt, werden die Ergebnisse auf NULL gesetzt.
Ist es ein 24/7 Markt, gibt die Funktion False und aller Resultate als NULL zurück.
Im Fehlerfall gibt die Funktion alle Werte als LONG-Max-Wert zurück.
Es ist möglich, der Funktion einen eigenen Timestamp als referenzpunkt mitzugeben. Ansonsten wird die Trade-Server-Zeit herangezogen.
Die Parameter session_begin, session_end und next_session können als datetime-werde übergeben werden. (datetime entspricht dem long-Typ)
//+------------------------------------------------------------------+ //| SymbolInfoSession() | //+------------------------------------------------------------------+ const bool SymbolInfoSessionTimes(const string symbol, long& session_begin, long& session_end, long& next_session, const bool quote_sessions = false, const long reference_time = NULL) { // Pre init MqlDateTime mql_time = { NULL }; const ulong time_current = (reference_time == NULL) ? TimeTradeServer(mql_time) : (ulong)reference_time; if( (reference_time > NULL) && (TimeToStruct(time_current, mql_time)) { session_begin = 0xFFFFFFFFFFFFFFFF; session_end = 0xFFFFFFFFFFFFFFFF; next_session = 0xFFFFFFFFFFFFFFFF; return(false); } // Local init ulong start = NULL; ulong finish = NULL; ulong day_start = time_current - (time_current % 0x0000000000015180) - 0x0000000000015180; ulong session_index = NULL; session_begin = NULL; session_end = NULL; next_session = NULL; // Loop search for(ulong cnt = NULL; (cnt < 0x08) && !_StopFlag; cnt++) { // Current time offset day_start += 0x0000000000015180; session_index = NULL; // Switch type of evaluation switch((uint)cnt) { // Find current session if any case 0x00: if(quote_sessions) { while( ((day_start + finish) <= time_current) && (mqlplus::SymbolInfoSessionQuote(symbol, DayOfWeekToEnum(mql_time.day_of_week + cnt), (int)(session_index++), start, finish)) && !_StopFlag); } else { while( ((day_start + finish) <= time_current) && (mqlplus::SymbolInfoSessionTrade(symbol, DayOfWeekToEnum(mql_time.day_of_week + cnt), (int)(session_index++), start, finish)) && !_StopFlag); } // Check results if( ((day_start + start) <= time_current) && ((day_start + finish) > time_current)) { session_begin = (long)(day_start + start); session_end = (long)(day_start + finish); } // Search for beginning of session if(session_begin > NULL) { // Init loop int session_index1 = NULL; int max_count = NULL; ulong local_begin = NULL; ulong local_end = NULL; // Loop search for(int cnt1 = (day_start == session_begin); (cnt1 < 0x08) && !_StopFlag; cnt1++) { // Init search loop day_start -= 0x0000000000015180 * ((cnt1 > NULL) && (session_index1 == NULL)); session_index1 = NULL; //local_begin = NULL; local_end = NULL; // Loop backwards if(quote_sessions) { while( ((session_index1 < max_count) || (max_count == NULL)) && (mqlplus::SymbolInfoSessionQuote(symbol, DayOfWeekToEnum(mql_time.day_of_week - cnt1), (int)(session_index1++), start, finish)) && ((long)(day_start + finish) <= session_begin) && !_StopFlag) { local_begin = (day_start + start); local_end = (day_start + finish); } } else { while( ((session_index1 < max_count) || (max_count == NULL)) && (mqlplus::SymbolInfoSessionTrade(symbol, DayOfWeekToEnum(mql_time.day_of_week - cnt1), (int)(session_index1++), start, finish)) && ((long)(day_start + finish) <= session_begin) && !_StopFlag) { local_begin = (day_start + start); local_end = (day_start + finish); } } // Repeat search on same day if more than one session if(session_begin == local_end) { session_begin = (long)(local_begin); cnt1 -= 1 * (session_index1 > 0x01); max_count = session_index1; } cnt1 |= 0xFF * (session_begin > (long)local_end); } // Reset day_start variable day_start = time_current - (time_current % 0x0000000000015180); } // Check for multiple sessions if( ((long)(day_start + start) > session_end) && (finish > NULL)) { next_session = (long)(day_start + start); return(true); } // Find next session default: if(quote_sessions) { if(!mqlplus::SymbolInfoSessionQuote(symbol, DayOfWeekToEnum(mql_time.day_of_week + cnt), (int)(session_index++), start, finish)) { continue; } } else { if(!mqlplus::SymbolInfoSessionTrade(symbol, DayOfWeekToEnum(mql_time.day_of_week + cnt), (int)(session_index++), start, finish)) { continue; } } // Next found session next_session = (long)(day_start + start) * (session_end < (long)(day_start + start)); session_end = (long)((session_end * (next_session > NULL)) + ((day_start + finish) * (next_session == NULL))); } if(next_session > NULL) { return(true); } } // Clear to zero as 24/7 sessions session_begin = NULL; session_end = NULL; next_session = NULL; // Return return(false); } //+------------------------------------------------------------------+ //| SymbolToString() | //+------------------------------------------------------------------+ template <typename T> const ENUM_DAY_OF_WEEK DayOfWeekToEnum(const T day_of_week) { switch(((uint)day_of_week) % 7) { case 0x01: return(MONDAY); case 0x02: return(TUESDAY); case 0x03: return(WEDNESDAY); case 0x04: return(THURSDAY); case 0x05: return(FRIDAY); case 0x06: return(SATURDAY); default: return(SUNDAY); } } //+------------------------------------------------------------------+ //| SymbolInfoSessionQuote() | //+------------------------------------------------------------------+ namespace mqlplus { const bool SymbolInfoSessionQuote(const string symbol, const ENUM_DAY_OF_WEEK day, const int session_index, datetime& start, datetime& finish) { start = NULL; finish = NULL; return(::SymbolInfoSessionQuote(symbol, day, session_index, start, finish)); } }; // Namespece mqlplus:: //+------------------------------------------------------------------+ //| SymbolInfoSessionTrade() | //+------------------------------------------------------------------+ namespace mqlplus { const bool SymbolInfoSessionTrade(const string symbol, const ENUM_DAY_OF_WEEK day, const int session_index, datetime& start, datetime& finish) { start = NULL; finish = NULL; return(::SymbolInfoSessionTrade(symbol, day, session_index, start, finish)); } }; // Namespece mqlplus::

- Freie Handelsapplikationen
- Über 8.000 Signale zum Kopieren
- Wirtschaftsnachrichten für die Lage an den Finanzmärkte
Sie stimmen der Website-Richtlinie und den Nutzungsbedingungen zu.
Hallo zusammen,
kann man im MT5 den Handelstag prüfen, also ob offen ist?
Ich möchte praktisch eine Strategie immer Freitags ausführen, aber wenn Freitag nicht geöffnet ist, dann eben Donnerstag.
Gruß
Manuel