MT自定义指标编程

发布时间 2023-11-09 09:43:41作者: 吾心依旧

一、如何创建自定义指标

 

二、自定义指标编程特点

(1)MT中对象属性设置的特点:

如果对类型A的对象属性进行设置,往往是这种格式:ASetDataType(index,ENUM_X,value);

DataType:属性值类型,

index:对象索引,

ENUM_X:属性枚举,

value:赋值

如对指标的第一条线设置

//--- 设置画线
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
//--- 设置线型
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_DOT);
//--- 设置线颜色
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrRed);
//--- 设置线粗细
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);
//--- 为线设置标签
   PlotIndexSetString(0,PLOT_LABEL,"Moving Average");

(2)自定义指标计算处理

int OnCalculate(){},在此方法中进行指标的计算处理,OnCalculate()有两种形态:
int  OnCalculate(
   const int        rates_total,       // 输入时间序列的大小
   const int        prev_calculated,   // 在前一个调用中处理过的柱形图数量
   const datetime&  time[],            // 时间数组
   const double&    open[],            // 开盘价数组
   const double&    high[],            // 最高价数组
   const double&    low[],             // 最低价数组
   const double&    close[],           // 收盘价数组
   const long&      tick_volume[],     // 报价量数组
   const long&      volume[],          // 真实交易量数组
   const int&       spread[]           // 点差数组
   );

int  OnCalculate(
   const int        rates_total,       // price[]数组大小
   const int        prev_calculated,   // 在前一个调用中处理过的柱形图数量
   const int        begin,             //price[]数组中,有意义数据开始的索引编号
   const double&    price[]            // 计算值数组
   );