如何编写均线多空变色指标? 新评论 oceanmt4wind 2020.05.08 08:06 以下代码在MT4中显示不了,请朋友们提点: //+------------------------------------------------------------------+ #property copyright "2005-2015, MetaQuotes Software Corp." #property link "http://www.mql4.com" #property description "Moving Average" #property strict #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Green int InpMAPeriod=56; // Period //--- indicator buffer double AscendLine[]; double DescendLine[]; double FullLine[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { int draw_begin=InpMAPeriod-1; IndicatorDigits(Digits); //--- check for input if(InpMAPeriod<2) return(INIT_FAILED); //--- drawing settings SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexDrawBegin(0,draw_begin); SetIndexDrawBegin(1,draw_begin); //--- indicator buffers mapping SetIndexBuffer(0,AscendLine); SetIndexBuffer(1,DescendLine); //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Moving Average | //+------------------------------------------------------------------+ 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[]) { //--- check for bars count if(rates_total<InpMAPeriod-1 || InpMAPeriod<2) return(0); //--- first calculation or number of bars was changed if(prev_calculated==0) { ArrayInitialize(AscendLine,0); ArrayInitialize(DescendLine,0); ArrayInitialize(FullLine,0); } //--- calculation CalculateEMA(rates_total,prev_calculated,close); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| exponential moving average | //+------------------------------------------------------------------+ void CalculateEMA(int rates_total,int prev_calculated,const double &price[]) { int i,limit; double SmoothFactor=2.0/(1.0+InpMAPeriod); //--- first calculation or number of bars was changed if(prev_calculated==0) { limit=InpMAPeriod; FullLine[0]=price[0]; for(i=1; i<limit; i++) FullLine[i]=price[i]*SmoothFactor+FullLine[i-1]*(1.0-SmoothFactor); } else limit=prev_calculated-1; //--- main loop for(i=limit; i<rates_total && !IsStopped(); i++) { FullLine[i]=price[i]*SmoothFactor+FullLine[i-1]*(1.0-SmoothFactor); AscendLine[i]=EMPTY_VALUE; DescendLine[i]=EMPTY_VALUE; if(FullLine[i-1]<=FullLine[i]) { AscendLine[i]=FullLine[i]; } else { DescendLine[i]=FullLine[i]; } } //--- } 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
以下代码在MT4中显示不了,请朋友们提点: