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

手工图表和交易工具包1 准备---结构描述和助手类

只看楼主收藏回复

我是一名手工交易者。 我在分析图表时更喜欢不用复杂的公式和指标,只用纯手工(即以图形方式)进行分析。 这有助于我更加灵活地进行交易,关注一些难以形式化的事情,如果我看到波动在增加或放缓,则可以轻松地在时间帧之间切换,并在入场交易之前就知道了可能的价格行为。
基本上,我使用趋势线的不同组合(草叉、扇形、水平、等等)。 为此,我创建了一套便捷的工具,可一键快速绘制趋势线。 现在,我希望与社区共享此工具。赫兹股票量化交易软件
视频演示。 它如何运行一般概念。 设定任务
故此,我们正在创建一套工具,该工具可帮助您利用键盘快捷键执行最频繁的操作。
可以实现哪些任务? 举例:
按下 “H” 键(“Horizontal”)绘制一条简单的水平线,而按下 “ i ” 则绘制一条垂直线(仅因为它看起来像一条垂直线)
从图表的任意点开始绘制一定长度(不是无限)的水平线
在距起点一定(任意)距离处绘制垂直线
l利用按键切换时间帧,并重新排列图表上的图层
在最近的极限点绘制预设价位的斐波那契扇形
在最近的极限点绘制趋势线;它们的长度应为端点之间距离的倍数;在某些情况下,该趋势线也可以是射线
绘制各种类型的安德鲁草叉(标准,Schiff,反向 Schiff 草叉 - 对于快速趋势)(请参阅 视频)
对于草叉、趋势线和扇形的极值点,应能自定义极值点的顺序(分立左、右两侧的柱线数量)
图形界面,可在不打开设置窗口的情况下自定义所需趋势线和极值点的参数
一组订单管理函数:基于存款百分比开立订单,在开立市价订单或没有设置触发止损价位的挂单时自动设置止损价位,启用按价位部分平仓,尾随止损,诸如此类
当然,大多数任务可以用脚本自动执行。 我完成了其中的几个。 您可在文章的附件里找到它们。 然而,我更喜欢另一种方式。赫兹股票量化交易软件
在智能交易系统或指标里,我们能够创建赫兹股票量化交易软件方法,包含针对任何事件的响应描述:击键、鼠标移动、图形对象的创建或删除。
这就是为什么我决定把所创建的程序作为一个包含文件的原因。 所有函数和变量都分布在若干个类里,从而令其更易于访问。 在这一点上,我只需要类即可方便地对函数进行分组。 这就是为什么在此首个实现中,我们将不使用诸如继承或工厂之类的复杂事物的原因。 这只是一个集合。
甚而,我想创建一个可以在 赫兹股票量化交易软件运行的跨平台类。
程序结构
该函数库包含五个相关文件。 所有文件都位于 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 方法中使用该变量。赫兹股票量化交易软件
连接需要两行:
//+------------------------------------------------------------------+//| The main Expert (file "Shortcuts-Main-Expert.mq5") |//+------------------------------------------------------------------+#include <Shortcuts\Shortcuts.mqh>// ...//+------------------------------------------------------------------+//| The ChartEvent function |//+------------------------------------------------------------------+void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {//--- shortcuts.OnChartEvent(id,lparam,dparam,sparam); }
第一行连接类文件。 第二行则将事件响应控制转移到该类。
之后,智能交易系统就准备就绪,可以进行编译并绘制指标线。
鼠标移动响应类
该类将存储当前光标位置的所有基本参数:坐标 X,Y(以像素和价格/时间为单位),指针所处的柱线序号等 - 所有这些都存储在 “ Mouse.mqh ” 文件当中。赫兹股票量化交易软件
//+------------------------------------------------------------------+//| Mouse.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"//+------------------------------------------------------------------+//| Mouse movement handling class |//+------------------------------------------------------------------+class CMouse { //--- Membersprivate: static int m_x; // X static int m_y; // Y static int m_barNumber; // Bar number static bool m_below; // Indication of a cursor above the price static bool m_above; // Indication of a cursor below the price static datetime m_currentTime; // Current time static double m_currentPrice;// Current price //--- Methodspublic: //--- Remembers the main parameters of the mouse cursor static void SetCurrentParameters( const int id, const long &lparam, const double &dparam, const string &sparam ); //--- Returns the X coordinate (in pixels) of the current cursor position static int X(void) {return m_x;} //--- Returns the Y coordinate (in pixels) of the current cursor position static int Y(void) {return m_y;} //--- Returns the price of the current cursor position static double Price(void) {return m_currentPrice;} //--- Returns the time of the current cursor position static datetime Time(void) {return m_currentTime;} //--- Returns the bar number of the current cursor position static int Bar(void) {return m_barNumber;} //--- Returns a flag showing that the price is below the Low of the current bar static bool Below(void) {return m_below;} //--- Returns a flag showing that the price is above the High of the current bar static bool Above(void) {return m_above;} };//---int CMouse::m_x=0;int CMouse::m_y=0;int CMouse::m_barNumber=0;bool CMouse::m_below=false;bool CMouse::m_above=false;datetime CMouse::m_currentTime=0;double CMouse::m_currentPrice=0;//+------------------------------------------------------------------+//| Remembers the main parameters for a mouse movement: coordinates |//| of cursor in pixels and price/time, whether the cursor is |//| above or below the price. |//|+-----------------------------------------------------------------+static void CMouse::SetCurrentParameters( const int id, const long &lparam, const double &dparam, const string &sparam) {//--- int window = 0;//--- ChartXYToTimePrice( 0,


IP属地:浙江1楼2023-07-12 15:10回复