学习EA,指标不会实时刷新数值

 

我学些EA,学了一些简单的语法,写了一个5日均线,然后和系统自带的SMA(5)进行比较,我发现系统自带的指标随着最后一个柱线的收盘价的变化,均线末端的值也发生变化,而我写的就不变化,要等一个周期走完才变化,不知道哪里有问题了

//+------------------------------------------------------------------+
//|                                                        MT3x3.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "http://www.mql4.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


#property indicator_buffers 1
#property indicator_color1     clrRed



double Dma3_H1[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//--- indicator buffers mapping
   IndicatorDigits(Digits());
   SetIndexStyle(0,DRAW_LINE);//设置画线形式
   SetIndexBuffer(0,Dma3_H1);//画线数组
  

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                               |
//+------------------------------------------------------------------+
int start()
  {
//---

  
  for(int i=0; i<=iBars("USDJPY",PERIOD_H1); i++){
      Dma3_H1[i]=iMA("USDJPY",PERIOD_H1,5,0,MODE_SMA,PRICE_CLOSE,i);
  }
//--- return value of prev_calculated for next call
   return(0);
  }
//+------------------------------------------------------------------+


 

 
huang:

我学些EA,学了一些简单的语法,写了一个5日均线,然后和系统自带的SMA(5)进行比较,我发现系统自带的指标随着最后一个柱线的收盘价的变化,均线末端的值也发生变化,而我写的就不变化,要等一个周期走完才变化,不知道哪里有问题了

//+------------------------------------------------------------------+
//|                                                        MT3x3.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "http://www.mql4.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


#property indicator_buffers 1
#property indicator_color1     clrRed



double Dma3_H1[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//--- indicator buffers mapping
   IndicatorDigits(Digits());
   SetIndexStyle(0,DRAW_LINE);//设置画线形式
   SetIndexBuffer(0,Dma3_H1);//画线数组
  

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                               |
//+------------------------------------------------------------------+
int start()
  {
//---

  
  for(int i=0; i<=iBars("USDJPY",PERIOD_H1); i++){
      Dma3_H1[i]=iMA("USDJPY",PERIOD_H1,5,0,MODE_SMA,PRICE_CLOSE,i);
  }
//--- return value of prev_calculated for next call
   return(0);
  }
//+------------------------------------------------------------------+


 你用的是收盘价,系统用的是实时

 
weiliang Li:
谢谢,对比了源码,IndicatorCounted 这个函数用了之后就可以了实时刷新了。
原因: