量化軟件:赫茲量化中結(jié)構(gòu)描述和助手類
在智能交易系統(tǒng)或指標(biāo)里,我們能夠創(chuàng)建?OnChartEvent?方法,包含針對任何事件的響應(yīng)描述:擊鍵、鼠標(biāo)移動(dòng)、圖形對象的創(chuàng)建或刪除。
這就是為什么我決定把所創(chuàng)建的程序作為一個(gè)包含文件的原因。 所有函數(shù)和變量都分布在若干個(gè)類里,從而令其更易于訪問。 在這一點(diǎn)上,我只需要類即可方便地對函數(shù)進(jìn)行分組。 這就是為什么在此首個(gè)實(shí)現(xiàn)中,我們將不使用諸如繼承或工廠之類的復(fù)雜事物的原因。 這只是一個(gè)集合。
甚而,我想創(chuàng)建一個(gè)可以在 MQL4 和 MQL5 中均可運(yùn)行的跨平臺(tái)類。
程序結(jié)構(gòu)
該函數(shù)庫包含五個(gè)相關(guān)文件。 所有文件都位于 Include 目錄中的 “Shortcuts” 文件夾下。 它們的名稱如圖所示:GlobalVariables.mqh,Graphics.mqh,Mouse.mqh,Shortcuts.mqh,Utilites.mqh。
函數(shù)庫主文件(Shortcuts.mqh)
程序的主文件是 "Shortcuts.mqh"。 按鍵響應(yīng)邏輯將寫入此文件之中。 這是應(yīng)該連接到智能交易系統(tǒng)的文件。 所有輔助文件也將包括在其中。
//+------------------------------------------------------------------+//|????????????????????????????????????????????????????Shortcuts.mqh |//|????????????????????????Copyright 2020, MetaQuotes Software Corp. |//|????????????????????????????https://www.mql5.com/ru/articles/7468 |//+------------------------------------------------------------------+#property copyright "Copyright 2020, MetaQuotes Software Corp."#property link??????"https://www.mql5.com/en/articles/7468"#include "GlobalVariables.mqh"#include "Mouse.mqh"#include "Utilites.mqh"#include "Graphics.mqh"//+------------------------------------------------------------------+//| The main control class of the program. It should be connected ? ?|//| to the Expert Advisor????????????????????????????????????????????|//+------------------------------------------------------------------+class CShortcuts??{private: ?? CGraphics???????? m_graphics;?? // Object for drawing m_graphicspublic: ???????????????????? CShortcuts(); ?? void??????????????OnChartEvent(const int id, ??????????????????????????????????const long &lparam, ??????????????????????????????????const double &dparam, ??????????????????????????????????const string &sparam); ??};//+------------------------------------------------------------------+//| Default constructor ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|//+------------------------------------------------------------------+CShortcuts::CShortcuts(void) ??{ ?? ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true); ??}//+------------------------------------------------------------------+//| Event handling function ?????????????????????????????????????????|//+------------------------------------------------------------------+void CShortcuts::OnChartEvent( ?? const int id, ?? const long &lparam, ?? const double &dparam, ?? const string &sparam ) ??{//---?? // This will contain the description of the events related to keystrokes?? // and mouse movements?? //??...??} }CShortcuts shortcuts;
該文件包含?CShortcuts?類描述。
在文件的開頭,已連接所有幫助類
該類只有兩個(gè)方法。 第一個(gè)是?OnChartEvent?事件響應(yīng)程序,該事件響應(yīng)程序?qū)⑻幚硭邪存I和鼠標(biāo)移動(dòng)事件。 第二個(gè)是默認(rèn)構(gòu)造函數(shù),可在其中處理鼠標(biāo)移動(dòng)。
在類描述之后,將創(chuàng)建一個(gè)?shortcuts?變量,當(dāng)連接函數(shù)庫時(shí),應(yīng)在智能交易系統(tǒng)主體的?OnChartEvent?方法中使用該變量。
連接需要兩行: