程序化交易吧 关注:3,286贴子:8,499
  • 0回复贴,共1

量化软件:赫兹量化中结构描述和助手类

只看楼主收藏回复

在智能交易系统或指标里,我们能够创建 OnChartEvent 方法,包含针对任何事件的响应描述:击键、鼠标移动、图形对象的创建或删除。
这就是为什么我决定把所创建的程序作为一个包含文件的原因。 所有函数和变量都分布在若干个类里,从而令其更易于访问。 在这一点上,我只需要类即可方便地对函数进行分组。 这就是为什么在此首个实现中,我们将不使用诸如继承或工厂之类的复杂事物的原因。 这只是一个集合。
甚而,我想创建一个可以在 MQL4 和 MQL5 中均可运行的跨平台类。
程序结构

该函数库包含五个相关文件。 所有文件都位于 Include 目录中的 “Shortcuts” 文件夹下。 它们的名称如图所示:GlobalVariables.mqh,Graphics.mqh,Mouse.mqh,Shortcuts.mqh,Utilites.mqh。
函数库主文件(Shortcuts.mqh)
程序的主文件是 "Shortcuts.mqh"。 按键响应逻辑将写入此文件之中。 这是应该连接到智能交易系统的文件。 所有辅助文件也将包括在其中。
//+------------------------------------------------------------------+//| 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 类描述。
在文件的开头,已连接所有帮助类
该类只有两个方法。 第一个是 OnChartEvent 事件响应程序,该事件响应程序将处理所有按键和鼠标移动事件。 第二个是默认构造函数,可在其中处理鼠标移动。
在类描述之后,将创建一个 shortcuts 变量,当连接函数库时,应在智能交易系统主体的 OnChartEvent 方法中使用该变量。
连接需要两行:


IP属地:浙江1楼2023-10-31 11:35回复