调用ZigZag显示

//+------------------------------------------------------------------+ 
//|                                              TestCopyBuffer3.mq5 | 
//|                        Copyright 2009, MetaQuotes Software Corp. | 
//|                                             https://www.mql5.com | 
//+------------------------------------------------------------------+ 
#property copyright "2009, MetaQuotes Software Corp." 
#property link      "https://www.mql5.com" 
#property version   "1.00" 
  
//#property indicator_separate_window 
#property indicator_chart_window
#property indicator_buffers 1 
#property indicator_plots   1 
//---- 图 MA 
#property indicator_label1  "MA" 
#property indicator_type1   DRAW_SECTION 
#property indicator_color1  clrRed 
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  1 
//--- 输入参量 
input bool               AsSeries=true; 
input int                period=15; 
input ENUM_MA_METHOD     smootMode=MODE_EMA; 
input ENUM_APPLIED_PRICE price=PRICE_CLOSE; 
input int                shift=0; 
//--- 指标缓冲区 
double                   MABuffer[]; 
int                      ma_handle; 
//+------------------------------------------------------------------+ 
//| 自定义指标初始化函数                                                | 
//+------------------------------------------------------------------+ 
int OnInit() 
  { 
//--- 指标缓冲区绘图 
   SetIndexBuffer(0,MABuffer,INDICATOR_DATA); 
   Print("Parameter AsSeries = ",AsSeries); 
   Print("Indicator buffer after SetIndexBuffer() is a timeseries = ", 
         ArrayGetAsSeries(MABuffer)); 
//--- 设置短小的指标名称 
   IndicatorSetString(INDICATOR_SHORTNAME,"MA("+period+")"+AsSeries); 
//--- 设置 AsSeries(依据输入参量) 
   ArraySetAsSeries(MABuffer,AsSeries); 
   Print("Indicator buffer after ArraySetAsSeries(MABuffer,true); is a timeseries = ", 
         ArrayGetAsSeries(MABuffer)); 
//--- 
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   ma_handle = iCustom(NULL, 0, "Examples\\ZigZag", 12, 5, 3);
   return(INIT_SUCCEEDED); 
  } 
//+------------------------------------------------------------------+ 
//| 自定义指标重复函数                                                  | 
//+------------------------------------------------------------------+ 
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[]) 
  { 
//--- 检测是否计算了所有数据 
   if(BarsCalculated(ma_handle)<rates_total) return(0); 
//--- 不复制所有数据 
   if(CopyBuffer(ma_handle,0,0,rates_total,MABuffer)<=0) return(0); 
//--- 为下次调用返回prev_calculated值 
   return(rates_total); 
  } 
//+------------------------------------------------------------------+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值