帮帮我,自定义的指标加载后,新的K线出来后,指标没有新的柱子画出来

 
#property strict

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_width1  3
#property indicator_color1 clrRed  

input int    周期=45;      

double ExtMovingBuffer[];
double biaozhuncha[];
double ZFENSHU[];

int OnInit(void)
  {

//--- 
   SetIndexLabel(0,"Z分数");
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ZFENSHU);
   
   SetIndexBuffer(1,biaozhuncha);
   SetIndexBuffer(2,ExtMovingBuffer);
  

//---
  SetIndexDrawBegin(0,周期);
   SetIndexDrawBegin(1,周期);
   SetIndexDrawBegin(2,周期);
//--- initialization done
   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(rates_total<=周期 || 周期<=0)
      return(0);
 
 
 ArraySetAsSeries(ExtMovingBuffer,1);
 ArraySetAsSeries(biaozhuncha,1);
 ArraySetAsSeries(ZFENSHU,1);


  int limit; 
     int counted_bars=IndicatorCounted(); 
     if(counted_bars<0) return(-1); 
     if(counted_bars>0) counted_bars--; 
     limit=Bars-counted_bars;

     for(int i=0; i<limit; i++) 
     {    
           ExtMovingBuffer[i]=iMA(NULL,0,周期,0,MODE_SMA,PRICE_CLOSE,i);
           biaozhuncha[i]=iStdDev(NULL,0,周期,0,MODE_SMA,PRICE_CLOSE,i);
           ZFENSHU[i]=(close[i]-ExtMovingBuffer[i])/biaozhuncha[i];
  
}  

  
      //Z分数=(需要计算的位置-平均数)/标准差

   return(rates_total);
  }
 

//

//+------------------------------------------------------------------+
//|                                                   test_Z分数.mq4 |
//|                                         Copyright 2022, fxMeter. |
//|                            https://www.mql5.com/en/users/fxmeter |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, fxMeter."
#property link      "https://www.mql5.com/en/users/fxmeter"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_width1  3
#property indicator_color1 clrRed

input int    周期=45;

double ExtMovingBuffer[];
double biaozhuncha[];
double ZFENSHU[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
   IndicatorBuffers(3);
   SetIndexLabel(0,"Z分数");
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ZFENSHU);
   SetIndexBuffer(1,biaozhuncha,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,ExtMovingBuffer,INDICATOR_CALCULATIONS);
//---
   SetIndexDrawBegin(0,周期);
   SetIndexDrawBegin(1,周期);
   SetIndexDrawBegin(2,周期);
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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(rates_total<=周期 || 周期<=0) return(0);
   int limit;
   if(prev_calculated<=0)limit = rates_total;
   else limit = rates_total - prev_calculated +1;

   for(int i=0; i<limit; i++)
   {
      ExtMovingBuffer[i]=iMA(NULL,0,周期,0,MODE_SMA,PRICE_CLOSE,i);
      biaozhuncha[i] = iStdDev(NULL,0,周期,0,MODE_SMA,PRICE_CLOSE,i);
      if(biaozhuncha[i]!=0.0)ZFENSHU[i]=(close[i]-ExtMovingBuffer[i])/biaozhuncha[i];
      else ZFENSHU[i]=0.0;
   }
   //Z分数=(需要计算的位置-平均数)/标准差
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
 

感谢您的帮助!

不过我发现INDICATOR_CALCULATIONS这个函数只在mql5才有。新人学习mt4的话,当初我自己调试这个代码怎么也想不到mql5中的这个函数。请问学习mt4编程有什么可靠的路径嘛,还有,有什么活跃的学习社区嘛

 
tsing #:

感谢您的帮助!

不过我发现INDICATOR_CALCULATIONS这个函数只在mql5才有。新人学习mt4的话,当初我自己调试这个代码怎么也想不到mql5中的这个函数。请问学习mt4编程有什么可靠的路径嘛,还有,有什么活跃的学习社区嘛

正确的路径是学习一遍C语言语法,再学习MT4/MT5编程,后面想玩得高级一点,就得学习面向对象编程的语法,也就是要学习C++语法。

官方论坛的英文和俄语板块就比较活跃。