ClassPack 是一個用於交易的輔助類,提供了一些常用的功能,包括檢查新柱形、刪除所有掛單、平倉所有持倉以及獲取當前時間和日期的字符串表示。這個類可以幫助交易者更方便地管理交易和時間。
- 檢查新柱形:
bool isnewbar()- 檢查是否有新柱形產生,如果有新柱形,返回true;否則返回false。 - 刪除所有掛單:
void delete_all_pending_orders()- 刪除所有掛單。 - 平倉所有持倉:
void close_all_positions()- 平倉所有持倉。 - 獲取當前時間:
string current_time() const- 獲取當前時間的字符串表示(包含日期和時間),返回格式為 "YYYY.MM.DD HH:MM:SS"。 - 獲取當前日期:
string current_time_date() const- 獲取當前日期的字符串表示,返回格式為 "YYYY.MM.DD"。 - 獲取當前時間(秒):
string current_time_seconds() const- 獲取當前時間(僅秒)的字符串表示,返回格式為 "HH:MM:SS"。
- 將
classpack.mqh文件放入 MetaTrader 5 的Include目錄中。 - 在你的專家顧問或指標中包含此文件:
#include <classpack.mqh> - 創建
ClassPack的實例以使用其功能:ClassPack CPack;
-
檢查新柱形:
if (CPack.isnewbar()) { // 有新柱形 }
-
刪除所有掛單:
CPack.delete_all_pending_orders();
-
平倉所有持倉:
CPack.close_all_positions();
-
獲取當前時間:
string currentTime = CPack.current_time();
-
獲取當前日期:
string currentDate = CPack.current_time_date();
-
獲取當前時間(秒):
string currentSeconds = CPack.current_time_seconds();
注意事項
使用此類時,請確保在適當的上下文中調用其方法,特別是在交易操作中。 在使用平倉和刪除掛單功能時,請謹慎操作,以免意外關閉或刪除重要的交易。