时间序列的疑问,请大家赐教

 

以下是手册里CopyBuffer函数的示例代码

初始化当中的ArraySetAsSeries()方法不起任何作用,不管AsSeries怎么设置,均线都不会倒置

对代码进行简单修改,加入缓冲区MA1Buffer并划线,对其进行如下赋值

int limit=ArraySize(MABuffer);

for(int i=0;i<limit;i++){

   MA1Buffer[i]=MABuffer[i];

}

此刻均线左右倒置了

//+------------------------------------------------------------------+
//|                                              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_buffers 1
#property indicator_plots   1
//---- 图 MA
#property indicator_label1  "MA"
#property indicator_type1   DRAW_LINE
#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));
//---
   ma_handle=iMA(Symbol(),0,period,shift,smootMode,price);
   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);
//--- 不复制所有数据
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<=0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      //--- 常常复制最后的值
      to_copy++;
     }
//--- 复制
   if(CopyBuffer(ma_handle,0,0,to_copy,MABuffer)<=0return(0);
//--- 为下次调用返回prev_calculated值
   return(rates_total);
  }
//+------------------------------------------------------------------+

原因: