下载MetaTrader 5
要添加评论,请登录注册
MQL5.community允许用户存储源代码在MQL5 存储。试一下吧!
hohooh
22
hohooh 2010.06.08 12:36 

各位前辈好,,
我写了一个指标,在历史回测时可以使用
但是数据一进来就出问题了,


我发现数据一进来, 会使我的Array产生奇怪的数字

真是不明所以 18:20:09 CRR_DMA GBPUSD,M1:  i= 1 BufferS[i]= 1.4415 Array_MA[1]= 1.4416 Array_MA[0]= 1.4415 Array_Price[0]= 1.4411 Array_Price[1]= 1.4419 18:21:00 CRR_DMA GBPUSD,M1:  i= 1 BufferS[i]= 1073741824.2211 Array_MA[1]= 2147483647 Array_MA[0]= 1073741824.2211 Array_Price[0]= 1.4421 Array_Price[1]= 2147483647 18:22:15 CRR_DMA GBPUSD,M1:  i= 1 BufferS[i]= 1073741824.2211 Array_MA[1]= 1073741824.2211 Array_MA[0]= 2147483647 Array_Price[0]= 2147483647 Array_Price[1]= 1.4421 18:23:00 CRR_DMA GBPUSD,M1:  i= 1 BufferS[i]= 1073741824.2208 Array_MA[1]= 2147483647 Array_MA[0]= 1073741824.2208 Array_Price[0]= 1.4416 Array_Price[1]= 2147483647 18:24:03 CRR_DMA GBPUSD,M1:  i= 1 BufferS[i]= 1073741824.2208 Array_MA[1]= 1073741824.2208 Array_MA[0]= 2147483647 Array_Price[0]= 2147483647 Array_Price[1]= 1.4416

hohooh
22
hohooh 2010.06.08 12:50  
//+------------------------------------------------------------------+
//|                                              Multi.Period.MA.mq4 |
//|                               Copyright ?2010, Vladimir Hlystov |
//|                                                cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2010, Vladimir Hlystov"
#property link      "http://cmillion.narod.ru"
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_width1 3  

extern int DMA_Len     = 2;
extern string Time_Info = "M1=1,M5=5,M15=15,M30=30,H1=60";
extern string Time_Info2 = "H4=240,D1=1440,W1=10080,MN1=43200";
extern int timeframe     = 2;
extern int BarsBackTest     = 3000;
//---- buffers
double DMA[];
double Array_Price[];
double Array_MA[];
//---- vars
int    count=0;
int    i,j,TT1=0,TT2=0;
datetime reftime=0;
//+------------------------------------------------------------------+
int init()
  {
  reftime=0;   
//---- indicator lines
   IndicatorDigits(Digits+2);
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);  
   SetIndexBuffer(0, DMA);   
   SetIndexBuffer(1,Array_Price);
   SetIndexBuffer(2,Array_MA);
   SetIndexLabel(0,"DMA");    
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);
   SetIndexEmptyValue(2,EMPTY_VALUE);
   SetIndexDrawBegin(0,25);

//----   
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
int start()
{
   if (Time[0] == reftime) return(0);
   reftime=Time[0];
   int counted_bars=IndicatorCounted();   
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   Print(Bars,"  ",IndicatorCounted());
   //========================================
   for(i=limit; i>0; i--)
   {      
      TT1=MathAbs(MathMod(Time[i+1],(timeframe*60)));
      TT2=MathAbs(MathMod(Time[i],(timeframe*60)));
      if (TT1>TT2)
      {            
         for(j=DMA_Len-1;j>=1;j--)
         {
            Array_Price[j]=Array_Price[j-1];
         }
            Array_Price[0]=iClose(NULL,0,i+1);
         //==================================            
         if (Array_Price[DMA_Len-1] != 0)
         {
            for(j=2;j>=1;j--)
            {
               Array_MA[j]=Array_MA[j-1];
            }
            Array_MA[0]=rMAonArray(Array_Price,DMA_Len);
         }
         DMA[i]=Array_MA[0];
           
      }
      else
      {
         DMA[i]=DMA[i+1];            
      }
  

      
      if(IndicatorCounted()>0 || i==1)
        { Print(" i= ",i," BufferS[i]= ",DMA[i]," Array_MA[1]= ",Array_MA[1],
               " Array_MA[0]= ",Array_MA[0]," Array_Price[0]= ",
               Array_Price[0]," Array_Price[1]= ",Array_Price[1]); }
        
         
      
   }   
   return(0);
  
}
//+------------------------------------------------------------------+

double rMAonArray(double Array1[],int var0)
{
   int var1=ArraySize(Array1);
   if (var0>var1) var0=var1;
   double sum=0;
   for (int k=0;k<var0;k++)
   {
      sum=sum+Array1[k];
   }
   return(sum/var0);
}
/
要添加评论,请登录注册