股票量化軟件:赫茲量化中多周期、多品種單緩沖區(qū)標(biāo)準(zhǔn)指標(biāo)的跨平臺(tái)性質(zhì)
改進(jìn)庫類
如同往常,首先,添加必要的文本消息。 之前,在最終的指標(biāo)程序的整個(gè)代碼里,我們會(huì)立即檢查由函數(shù)庫創(chuàng)建的指標(biāo)緩沖區(qū)與有關(guān)指標(biāo)緩沖區(qū)所需數(shù)量的相關(guān)性:
#property indicator_buffers 3 #property indicator_plots ? 1
進(jìn)而,在代碼中,函數(shù)庫創(chuàng)建了所有必需緩沖區(qū)之后,會(huì)執(zhí)行檢查:
//--- Check the number of buffers specified in the 'properties' block ? if(engine.BuffersPropertyPlotsTotal()!=indicator_plots) ? ? ?Alert(TextByLanguage("Attention! Value of \"indicator_plots\" should be "),engine.BuffersPropertyPlotsTotal()); ? if(engine.BuffersPropertyBuffersTotal()!=indicator_buffers) ? ? ?Alert(TextByLanguage("Attention! Value of \"indicator_buffers\" should be "),engine.BuffersPropertyBuffersTotal());
把針對(duì) MQL4 的兼容性檢查稍微改進(jìn),并將其移至函數(shù)庫當(dāng)中。 將檢查時(shí)顯示的文本放在函數(shù)庫中的相應(yīng)位置 - 在文件 \MQL5\Include\DoEasy\Data.mqh。 并加入新消息的索引:
//--- CEngine ? MSG_ENG_NO_TRADE_EVENTS, ? ? ? ? ? ? ? ? ? ? ? ? ? // There have been no trade events since the last launch of EA ? MSG_ENG_FAILED_GET_LAST_TRADE_EVENT_DESCR, ? ? ? ? // Failed to get description of the last trading event ? MSG_ENG_FAILED_GET_MARKET_POS_LIST, ? ? ? ? ? ? ? ?// Failed to get the list of open positions ? MSG_ENG_FAILED_GET_PENDING_ORD_LIST, ? ? ? ? ? ? ? // Failed to get the list of placed orders ? MSG_ENG_NO_OPEN_POSITIONS, ? ? ? ? ? ? ? ? ? ? ? ? // No open positions ? MSG_ENG_NO_PLACED_ORDERS, ? ? ? ? ? ? ? ? ? ? ? ? ?// No placed orders ? MSG_ENG_ERR_VALUE_PLOTS, ? ? ? ? ? ? ? ? ? ? ? ? ? // Attention! Value \"indicator_plots\" must be ? MSG_ENG_ERR_VALUE_ORDERS, ? ? ? ? ? ? ? ? ? ? ? ? ?// Attention! Value \"indicator_buffers\" must be
及與新添加的索引相對(duì)應(yīng)的消息文本:
//--- CEngine ? {"There have been no trade events since the last launch of EA"}, ? {"Failed to get the description of the last trading event"}, ? {"Failed to get open positions list"}, ? {"Failed to get pending orders list"}, ? {"No open positions"}, ? {"No placed orders"}, ? {"Attention! Value of \"indicator_plots\" should be "}, ? {"Attention! Value of \"indicator_buffers\" should be "},
包含程序輸入數(shù)據(jù)的文件稱為 InpDatas.mqh... 遵循英語語法將其調(diào)整為正確的名稱(我為文件命名時(shí)犯了一個(gè)錯(cuò)誤)。 現(xiàn)在,該文件將稱之為:\MQL5\Include\DoEasy\InpData.mqh。 簡(jiǎn)單地在其所在的文件夾中重命名它即可。
此文件已在文件 Data.mqh(我們正在編輯)中連接到函數(shù)庫,調(diào)整包含代碼:
//+------------------------------------------------------------------+ //| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Data.mqh | //| ? ? ? ? ? ? ? ? ? ? ? ?Copyright 2020, MetaQuotes Software Corp. | //| ? ? ? ? ? ? ? ? ? ? ? ? ? ? https://mql5.com/en/users/artmedia70 | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link ? ? ?"https://mql5.com/en/users/artmedia70" //+------------------------------------------------------------------+ //| Include files ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ #include "InpData.mqh" //+------------------------------------------------------------------+
我們開始實(shí)現(xiàn)跨平臺(tái)特性。
//+------------------------------------------------------------------+ //| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ToMQL4.mqh | //| ? ? ? ? ? ? ?Copyright 2017, Artem A. Trishkin, Skype artmedia70 | //| ? ? ? ? ? ? ? ? ? ? ? ? https://www.mql5.com/en/users/artmedia70 | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, Artem A. Trishkin, Skype artmedia70" #property link ? ? ?"https://www.mql5.com/en/users/artmedia70" #property strict #ifdef __MQL4__ //+------------------------------------------------------------------+ //| Error codes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ #define ERR_SUCCESS ? ? ? ? ? ? ? ? ? ? ? (ERR_NO_ERROR) #define ERR_MARKET_UNKNOWN_SYMBOL ? ? ? ? (ERR_UNKNOWN_SYMBOL) #define ERR_ZEROSIZE_ARRAY ? ? ? ? ? ? ? ?(ERR_ARRAY_INVALID) #define ERR_MAIL_SEND_FAILED ? ? ? ? ? ? ?(ERR_SEND_MAIL_ERROR) #define ERR_NOTIFICATION_SEND_FAILED ? ? ?(ERR_NOTIFICATION_ERROR) #define ERR_FTP_SEND_FAILED ? ? ? ? ? ? ? (ERR_FTP_ERROR) //+------------------------------------------------------------------+ //| Order types, filling policy, period, reasons ? ? ? ? ? ? ? ? ? ? | //+-------------------------------------------------------------------+ #define SYMBOL_EXPIRATION_GTC ? ? ? ? ? ? (1) #define SYMBOL_EXPIRATION_DAY ? ? ? ? ? ? (2) #define SYMBOL_EXPIRATION_SPECIFIED ? ? ? (4) #define SYMBOL_EXPIRATION_SPECIFIED_DAY ? (8) //+------------------------------------------------------------------+ //| Flags of allowed order filling modes ? ? ? ? ? ? ? ? ? ? ? ? ? ? | //+------------------------------------------------------------------+ #define SYMBOL_FILLING_FOK ? ? ? ? ? ? ? ?(1) #define SYMBOL_FILLING_IOC ? ? ? ? ? ? ? ?(2) //+------------------------------------------------------------------+ //| The flags of allowed order types ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | //+------------------------------------------------------------------+ #define SYMBOL_ORDER_MARKET ? ? ? ? ? ? ? (1) #define SYMBOL_ORDER_LIMIT ? ? ? ? ? ? ? ?(2) #define SYMBOL_ORDER_STOP ? ? ? ? ? ? ? ? (4) #define SYMBOL_ORDER_STOP_LIMIT ? ? ? ? ? (8) #define SYMBOL_ORDER_SL ? ? ? ? ? ? ? ? ? (16) #define SYMBOL_ORDER_TP ? ? ? ? ? ? ? ? ? (32) #define SYMBOL_ORDER_CLOSEBY ? ? ? ? ? ? ?(64) //+------------------------------------------------------------------+ //| Indicator lines IDs ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+--------------+ //| Margin calculation mode ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ //--- the code has been removed for the sake of space //+------------------------------------------------------------------+ //| Pf selected position ? ? ? ? ? ? ? ? ? ? ? ? ? ? | //+------------------------------------------------------------------+ //--- the code has been removed for the sake of space //+------------------------------------------------------------------+ //| String properties of selected position ? ? ? ? ? ? ? ? ? ? ? ? ? | //+------------------------------------------------------------------+ //--- the code has been removed for the sake of space //+------------------------------------------------------------------+ //| Technical indicator types ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ enum ENUM_INDICATOR ?{ ? IND_AC ? ? ? ? = 5, //+------------------------------------------------------------------+ //| Trade request structure ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| //+------------------------------------------------------------------+ //--- the code has been further removed for the sake of space #endif
早前,該方法整體編寫在類主體中,其可立即返回已計(jì)算的數(shù)據(jù)量:
? ENUM_INDICATOR ? ?IndicatorType(void) ? ? ? ? ? ? ? ? ? ? ? const { return (ENUM_INDICATOR)this.GetProperty(BUFFER_PROP_IND_TYPE); ? ? ? ?} ? string ? ? ? ? ? ?IndicatorName(void) ? ? ? ? ? ? ? ? ? ? ? const { return this.GetProperty(BUFFER_PROP_IND_NAME); ? ? ? ? ? ? ? ? ? ? ? ?} ? string ? ? ? ? ? ?IndicatorShortName(void) ? ? ? ? ? ? ? ? ?const { return this.GetProperty(BUFFER_PROP_IND_NAME_SHORT); ? ? ? ? ? ? ? ? ?} ? int ? ? ? ? ? ? ? IndicatorBarsCalculated(void) ? ? ? ? ? ? const { return ::BarsCalculated((int)this.GetProperty(BUFFER_PROP_IND_HANDLE));} ? int ? ? ? ? ? ? ? IndicatorLineAdditionalNumber(void) ? ? ? const { return (int)this.GetProperty(BUFFER_PROP_IND_LINE_ADDITIONAL_NUM); ? ?} ? int ? ? ? ? ? ? ? IndicatorLineMode(void) ? ? ? ? ? ? ? ? ? const { return (int)this.GetProperty(BUFFER_PROP_IND_LINE_MODE); ? ? ? ? ? ? ?}
... 并將其實(shí)現(xiàn)移到類主體之外:
//+------------------------------------------------------------------+ //| Return the number of standard indicator calculated bars ? ? ? ? ?| //+------------------------------------------------------------------+ int CBuffer::IndicatorBarsCalculated(void) ?{ ? return(#ifdef __MQL5__ ::BarsCalculated((int)this.GetProperty(BUFFER_PROP_IND_HANDLE)) #else ::Bars(this.Symbol(),this.Timeframe()) #endif); ?} //+------------------------------------------------------------------