用MT4的MetaEditor编译mql5代码时出现了错误,请问该怎样才能让编译通过?

 

我想把一个MT5的指标用在MT4平台上,于是把 mql5代码 复制到MT4平台的MetaEditor中编译,结果出现3个错误。请教怎样修改才能让编译通过?

mql5代码如下:


//------------------------------------------------------------------
#property copyright   "© mladen, 2018"
#property link        "mladenfx@gmail.com"
#property version     "1.00"
#property description "Normalized MACD"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots   2
#property indicator_label1  "Normalized MACD"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  clrDodgerBlue,clrSandyBrown
#property indicator_width1  2
#property indicator_label2  "Normalized MACD signal line"
#property indicator_type2   DRAW_COLOR_LINE
#property indicator_color2  clrDodgerBlue,clrSandyBrown
#property indicator_style2  STYLE_DOT
//
//--- input parameters
//
input int                inpFastPeriod   = 12;           // MACD fast period
input int                inpSlowPeriod   = 26;           // MACD slow period
input int                inpMacdSignal   = 9;            // Signal period
input ENUM_APPLIED_PRICE inpPrice        = PRICE_CLOSE;  // Price
input int                inpSmoothPeriod = 5;            // Smoothing period
input int                inpNormPeriod   = 20;           // Normalization period
//
//--- indicator buffers
//
double val[],valc[],sig[],sigc[],macd[],emaf[],emas[];
double ª_alphaf,ª_alphas,ª_alphasig,ª_alphasm;

//------------------------------------------------------------------
// Custom indicator initialization function
//------------------------------------------------------------------
int OnInit()
{
   SetIndexBuffer(0,val ,INDICATOR_DATA);
   SetIndexBuffer(1,valc,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,sig ,INDICATOR_DATA);
   SetIndexBuffer(3,sigc,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4,macd,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,emaf,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,emas,INDICATOR_CALCULATIONS);
         ª_alphaf   = 2.0/(1.0+MathMax(inpFastPeriod,1));
         ª_alphas   = 2.0/(1.0+MathMax(inpSlowPeriod,1));
         ª_alphasig = 2.0/(1.0+MathMax(inpMacdSignal,1));
         ª_alphasm  = 2.0/(1.0+MathMax(inpSmoothPeriod,1));
   
   //---
            
   IndicatorSetString(INDICATOR_SHORTNAME,"Normalized MACD ("+(string)inpFastPeriod+","+(string)inpSlowPeriod+","+(string)inpMacdSignal+")");
   return(INIT_SUCCEEDED);
}
//------------------------------------------------------------------
// Custom indicator de-initialization function
//------------------------------------------------------------------
void OnDeinit(const int reason) { return; }
//------------------------------------------------------------------
// Custom iteration function
//------------------------------------------------------------------
//
//---
//

#define _setPrice(_priceType,_target,_index) \
   { \
   switch(_priceType) \
   { \
      case PRICE_CLOSE:    _target = close[_index];                                              break; \
      case PRICE_OPEN:     _target = open[_index];                                               break; \
      case PRICE_HIGH:     _target = high[_index];                                               break; \
      case PRICE_LOW:      _target = low[_index];                                                break; \
      case PRICE_MEDIAN:   _target = (high[_index]+low[_index])/2.0;                             break; \
      case PRICE_TYPICAL:  _target = (high[_index]+low[_index]+close[_index])/3.0;               break; \
      case PRICE_WEIGHTED: _target = (high[_index]+low[_index]+close[_index]+close[_index])/4.0; break; \
      default : _target = 0; \
   }}
//
//---
//

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[])
{                
   int i=(prev_calculated>0?prev_calculated-1:0); for (; i<rates_total && !_StopFlag; i++)
   {
      double _price; _setPrice(inpPrice,_price,i);
         emaf[i] = (i>0) ? emaf[i-1]+ª_alphaf*(_price-emaf[i-1]) : _price;
         emas[i] = (i>0) ? emas[i-1]+ª_alphas*(_price-emas[i-1]) : _price;
         macd[i] = emaf[i]-emas[i];
         
         //
         //---
         //
         
         int _start = (i>inpNormPeriod) ? i-inpNormPeriod+1 : 0;
            double _max = macd[ArrayMaximum(macd,_start,inpNormPeriod)];            
            double _min = macd[ArrayMinimum(macd,_start,inpNormPeriod)];            
            double _nval = (_min!=_max) ? 2.0*(macd[i]-_min)/(_max-_min)-1.0 : 0;
         val[i]  = (i>0) ? val[i-1] + ª_alphasm*(_nval-val[i-1]) : 0;
         valc[i] = (i>0) ? (val[i]>val[i-1]) ? 0 : 1 : 0;
         sig[i]  = (i>0) ? sig[i-1] + ª_alphasig*(val[i]-sig[i-1]) : 0;
         sigc[i] = (val[i]>sig[i]) ? 0 : 1;
   }          
   return(rates_total);

报错如图:

error

附加的文件:
1.mq4  11 kb
 
【如何防止机器人误判】讨论代码时请使用代码表述功能
【如何防止机器人误判】讨论代码时请使用代码表述功能
  • 2023.06.13
  • www.mql5.com
大家好,我是官网版主。 官网内部有机器人辅助管理,目的是自动下架一些有误导性的内容。 内容过长,或同一个IP多次注册,容易导致机器人误判,而被无辜删帖。 如果您被无故删帖,我们对这种体验感到万分抱歉。 为了防止机器人误判,请在讨论代码的时候使用代码表述功能。(如图) 感谢您的配合...
 

//------------------------------------------------------------------
#property copyright   "© mladen, 2018"
#property link        "mladenfx@gmail.com"
#property version     "1.00"
#property description "Normalized MACD"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots   2
#property indicator_label1  "Normalized MACD"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  clrDodgerBlue,clrSandyBrown
#property indicator_width1  2
#property indicator_label2  "Normalized MACD signal line"
#property indicator_type2   DRAW_COLOR_LINE
#property indicator_color2  clrDodgerBlue,clrSandyBrown
#property indicator_style2  STYLE_DOT
//
//--- input parameters
//
input int                inpFastPeriod   = 12;           // MACD fast period
input int                inpSlowPeriod   = 26;           // MACD slow period
input int                inpMacdSignal   = 9;            // Signal period
input ENUM_APPLIED_PRICE inpPrice        = PRICE_CLOSE;  // Price
input int                inpSmoothPeriod = 5;            // Smoothing period
input int                inpNormPeriod   = 20;           // Normalization period
//
//--- indicator buffers
//
double val[],valc[],sig[],sigc[],macd[],emaf[],emas[];
double ª_alphaf,ª_alphas,ª_alphasig,ª_alphasm;

//------------------------------------------------------------------
// Custom indicator initialization function
//------------------------------------------------------------------
int OnInit()
{
   SetIndexBuffer(0,val ,INDICATOR_DATA);
   SetIndexBuffer(1,valc,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,sig ,INDICATOR_DATA);
   SetIndexBuffer(3,sigc,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4,macd,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,emaf,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,emas,INDICATOR_CALCULATIONS);
         ª_alphaf   = 2.0/(1.0+MathMax(inpFastPeriod,1));
         ª_alphas   = 2.0/(1.0+MathMax(inpSlowPeriod,1));
         ª_alphasig = 2.0/(1.0+MathMax(inpMacdSignal,1));
         ª_alphasm  = 2.0/(1.0+MathMax(inpSmoothPeriod,1));
   
   //---
            
   IndicatorSetString(INDICATOR_SHORTNAME,"Normalized MACD ("+(string)inpFastPeriod+","+(string)inpSlowPeriod+","+(string)inpMacdSignal+")");
   return(INIT_SUCCEEDED);
}
//------------------------------------------------------------------
// Custom indicator de-initialization function
//------------------------------------------------------------------
void OnDeinit(const int reason) { return; }
//------------------------------------------------------------------
// Custom iteration function
//------------------------------------------------------------------
//
//---
//

#define _setPrice(_priceType,_target,_index) \
   { \
   switch(_priceType) \
   { \
      case PRICE_CLOSE:    _target = close[_index];                                              break; \
      case PRICE_OPEN:     _target = open[_index];                                               break; \
      case PRICE_HIGH:     _target = high[_index];                                               break; \
      case PRICE_LOW:      _target = low[_index];                                                break; \
      case PRICE_MEDIAN:   _target = (high[_index]+low[_index])/2.0;                             break; \
      case PRICE_TYPICAL:  _target = (high[_index]+low[_index]+close[_index])/3.0;               break; \
      case PRICE_WEIGHTED: _target = (high[_index]+low[_index]+close[_index]+close[_index])/4.0; break; \
      default : _target = 0; \
   }}
//
//---
//

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[])
{                
   int i=(prev_calculated>0?prev_calculated-1:0); for (; i<rates_total && !_StopFlag; i++)
   {
      double _price; _setPrice(inpPrice,_price,i);
         emaf[i] = (i>0) ? emaf[i-1]+ª_alphaf*(_price-emaf[i-1]) : _price;
         emas[i] = (i>0) ? emas[i-1]+ª_alphas*(_price-emas[i-1]) : _price;
         macd[i] = emaf[i]-emas[i];
         
         //
         //---
         //
         
         int _start = (i>inpNormPeriod) ? i-inpNormPeriod+1 : 0;
            double _max = macd[ArrayMaximum(macd,_start,inpNormPeriod)];            
            double _min = macd[ArrayMinimum(macd,_start,inpNormPeriod)];            
            double _nval = (_min!=_max) ? 2.0*(macd[i]-_min)/(_max-_min)-1.0 : 0;
         val[i]  = (i>0) ? val[i-1] + ª_alphasm*(_nval-val[i-1]) : 0;
         valc[i] = (i>0) ? (val[i]>val[i-1]) ? 0 : 1 : 0;
         sig[i]  = (i>0) ? sig[i-1] + ª_alphasig*(val[i]-sig[i-1]) : 0;
         sigc[i] = (val[i]>sig[i]) ? 0 : 1;
   }          
   return(rates_total);
 
MT4 MT5指標編程不一樣 建議你看一下幫助文件