//
//+------------------------------------------------------------------+ //| 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编程有什么可靠的路径嘛,还有,有什么活跃的学习社区嘛