MT5 iMA

iMA

函数返回移动平均数指标处理器。只有一个缓冲区。

int  iMA(
   string               symbol,            // 交易品种名称
   ENUM_TIMEFRAMES      period,            // 周期
   int                  ma_period,         // 平均周期
   int                  ma_shift,          // 平移
   ENUM_MA_METHOD       ma_method,         // 平滑类型
   ENUM_APPLIED_PRICE   applied_price      // 价格或者处理程序类型
   );

参量

symbol

[in] 证券交易品种名称,数据用来计算指标。 NULL 值代表当前交易品种。

period

[in] 周期值可以是 ENUM_TIMEFRAMES 值中的一个,0代表当前时间表。

ma_period

[in] 计算移动平均数的平均周期。

ma_shift

[in]  与价格图表有关的指标变化。

ma_method

[in]  平滑类型。可以是 ENUM_MA_METHOD 值中的一个。

applied_price

[in]  使用价格。可以是任意 ENUM_APPLIED_PRICE 价格常量或者另外指标处理器。

返回值

返回特殊技术指标处理器,失败返回 INVALID_HANDLE. 计算机内存从不使用的指标中释放,使用指标处理程序传递到的函数 IndicatorRelease()

例如:

//+------------------------------------------------------------------+
//|                                                     Demo_iMA.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "The indicator demonstrates how to obtain data"
#property description "of indicator buffers for the iMA technical indicator."
#property description "A symbol and timeframe used for calculation of the indicator,"
#property description "are set by the symbol and period parameters."
#property description "The method of creation of the handle is set through the 'type' parameter (function type)."
#property description "All other parameters like in the standard Moving Average."
 
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- iMA 标图
#property indicator_label1  "iMA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//+------------------------------------------------------------------+
//| 枚举处理创建方法                                                   |
//+------------------------------------------------------------------+
enum Creation
  {
   Call_iMA,               // 使用iMA
   Call_IndicatorCreate    // 使用IndicatorCreate
  };
//--- 输入参数
input Creation             type=Call_iMA;                // 函数类型
input int                  ma_period=10;                 // ma周期
input int                  ma_shift=0;                   // 移动
input ENUM_MA_METHOD       ma_method=MODE_SMA;           // 平滑类型
input ENUM_APPLIED_PRICE   applied_price=PRICE_CLOSE;    // 价格类型
input string               symbol=" ";                   // 交易品种 
input ENUM_TIMEFRAMES      period=PERIOD_CURRENT;        // 时间帧
//--- 指标缓冲区
double         iMABuffer[];
//--- 存储iMA指标处理程序的变量
int    handle;
//--- 存储变量
string name=symbol;
//--- 图表上的指标名称
string short_name;
//--- 我们将在移动平均指标中保持值的数量
int    bars_calculated=0;
//+------------------------------------------------------------------+
//| 自定义指标初始化函数                                                |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- 分配指标缓冲区数组
   SetIndexBuffer(0,iMABuffer,INDICATOR_DATA);
//--- 设置移动
   PlotIndexSetInteger(0,PLOT_SHIFT,ma_shift);   
//--- 定义绘制指标的交易品种  
   name=symbol;
//--- 删除向左和向右的空格
   StringTrimRight(name);
   StringTrimLeft(name);
//--- 如果它返回 'name' 字符串的零长度
   if(StringLen(name)==0)
     {
      //--- 获得指标附属的图表交易品种
      name=_Symbol;
     }
//--- 创建指标处理程序
   if(type==Call_iMA)
      handle=iMA(name,period,ma_period,ma_shift,ma_method,applied_price);
   else
     {
      //--- 以指标参数填充结构
      MqlParam pars[4];
      //--- 周期
      pars[0].type=TYPE_INT;
      pars[0].integer_value=ma_period;
      //--- 移动
      pars[1].type=TYPE_INT;
      pars[1].integer_value=ma_shift;
      //--- 平滑类型
      pars[2].type=TYPE_INT;
      pars[2].integer_value=ma_method;
      //--- 价格类型
      pars[3].type=TYPE_INT;
      pars[3].integer_value=applied_price;
      handle=IndicatorCreate(name,period,IND_MA,4,pars);
     }
//--- 如果没有创建处理程序
   if(handle==INVALID_HANDLE)
     {
      

转载于:https://www.cnblogs.com/anlewang/p/10186769.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值