期货量化软件:赫兹量化中的振荡指标

概述
将指标包括到EA中并在EA中使用指标缓冲区中的数据是一项相当简单的任务,尽管这需要不断浏览参考资料。我们需要记住传递给指标创建函数的所有参数,将其中一些参数形式化为EA输入,引入有效性检查等。为了获得数据,我们需要编写函数,从所需的柱形中返回必要的数据。所有这些都涉及到花费时间访问帮助、将所需变量输入EA、编写用于接收和监控数据以确定信号的函数等。

在恐慌性抛售导致价格暴跌后,平均真实范围通常会在市场底部达到很高的值。该指标的低值通常适用于市场顶部和盘整期间发生的长期横盘运动。它可以根据与其他波动性指标相同的规则进行预测。平均真实范围可以根据与其他波动性指标相同的原则进行解释。基于该指标的预测原理可以用以下方式表述:指标的值越高,趋势变化的概率越高;指标的值越低,趋势的变化就越弱。

参数
该指标只有一个可调参数:移动平均平滑周期。默认值为14。

让我们达成共识,所有指标输入参数都将被指定为可自定义的EA参数。

创建一个空的EA模板:
//+------------------------------------------------------------------+
//|                                            TestOscillatorATR.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- input parameters
input uint     InpPeriod=14;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+

我们将只在全局级别输入代码:变量和函数。在OnInit()和OnDeinit()处理函数中,设置指标参数的初始化和控制,以及指标句柄的创建和删除。测试EA将使用一个仪表板,显示从指示器接收的数据以及指示器线路状态的描述。OnChartEvent()EA处理函数仅设置用于处理面板的事件。换言之,为了完全处理EA中的指标,我们只需要使用创建的变量的示例、它们的初始化、指标句柄的创建和删除,以及从任何指标缓冲区接收数据的通用函数。示例中的其他一切都只是与面板一起工作。

将描述添加到输入参数和用于创建指标以及使用它的全局变量:

//--- input parameters
input uint  InpPeriod   =  14;   /* ATR Period  */
//--- global variables
int      handle=INVALID_HANDLE;  // Indicator handle
int      period=0;               // ATR calculation period
int      ind_digits=0;           // Number of decimal places in the indicator values
string   ind_title;              // Indicator description

我们创建了用于指标和EA的仪表板。该类现在已经进行了轻微修改,因此可以创建任意数量的面板来显示各种数据。我们不会在这里描述所做的更改,但稍后我们会回到它们。在随后的文章中,我们将简要介绍所做的更改和改进。要测试本文中的EA,面板类文件应位于\MQL5\Include\Dashboard.mqh中。带有面板类源代码的文件与测试EA文件一起附在文章中。

将仪表板文件包括在EA代码中并设置用于处理仪表板的全局变量:

#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- includes
#include <Dashboard\Dashboard.mqh>
//--- input parameters
input uint  InpPeriod   =  14;   /* ATR Period  */
//--- global variables
int      handle=INVALID_HANDLE;  // Indicator handle
int      period=0;               // ATR calculation period
int      ind_digits=0;           // Number of decimal places in the indicator values
string   ind_title;              // Indicator description
//--- variables for the panel
int      mouse_bar_index;        // Index of the bar the data is taken from
CDashboard *panel=NULL;          // Pointer to the panel object

上面我们研究了对指标线状态进行分类的可能选项。我认为,最方便的事情是创建一个具有所有可能选项的枚举,并从函数接收结果,该函数确定具有该枚举类型的变量中指标行的状态。让我们在全局区域中创建这样一个枚举并获得以下标题:

#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- includes
#include <Dashboard\Dashboard.mqh>
//--- enums
enum ENUM_LINE_STATE
  {
   LINE_STATE_NONE,        // Undefined state
   LINE_STATE_UP,          // Upward
   LINE_STATE_DOWN,        // Downward
   LINE_STATE_TURN_UP,     // Upward reversal
   LINE_STATE_TURN_DOWN,   // Downward reversal
   LINE_STATE_STOP_UP,     // Upward stop
   LINE_STATE_STOP_DOWN,   // Downward stop
   LINE_STATE_ABOVE,       // Above value
   LINE_STATE_UNDER,       // Below value
   LINE_STATE_CROSS_UP,    // Crossing value upwards
   LINE_STATE_CROSS_DOWN,  // Crossing value downwards
   LINE_STATE_TOUCH_BELOW, // Touching value from below 
   LINE_STATE_TOUCH_ABOVE, // Touch value from above
   LINE_STATE_EQUALS,      // Equal to value
  };
//--- input parameters
input uint  InpPeriod   =  14;   /* ATR Period  */
//--- global variables
int      handle=INVALID_HANDLE;  // Indicator handle
int      period=0;               // ATR calculation period
int      ind_digits=0;           // Number of decimal places in the indicator values
string   ind_title;              // Indicator description
//--- variables for the panel
int      mouse_bar_index;        // Index of the bar the data is taken from
CDashboard *panel=NULL;          // Pointer to the panel object
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值