求助 布林轨开始部分没有显示 如何解决 新评论 niepan.syl 2019.05.09 05:40 你好 MT5自带的布林轨在月线中 比如黄金现货 历史数据的最开始的25根K线是没有布林轨的值的 或者说没有布林轨覆盖的 这是为什么 如何能够让最初的那些K线也有画出布林轨 谢谢下面附上布林轨公式 参数设置是26 2 附上布林轨不显示部分的截图//+------------------------------------------------------------------+ //| BB.mq5 | //| Copyright 2009-2017, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009-2017, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property description "Bollinger Bands" #include <MovingAverages.mqh> //--- #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 3 #property indicator_type1 DRAW_LINE #property indicator_color1 LightSeaGreen #property indicator_type2 DRAW_LINE #property indicator_color2 LightSeaGreen #property indicator_type3 DRAW_LINE #property indicator_color3 LightSeaGreen #property indicator_label1 "Bands middle" #property indicator_label2 "Bands upper" #property indicator_label3 "Bands lower" //--- input parametrs input int InpBandsPeriod=26; // Period input int InpBandsShift=0; // Shift input double InpBandsDeviations=2.0; // Deviation //--- global variables int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; int ExtPlotBegin=0; //---- indicator buffer double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtStdDevBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- check for input values if(InpBandsPeriod<2) { ExtBandsPeriod=20; printf("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod); } else ExtBandsPeriod=InpBandsPeriod; if(InpBandsShift<0) { ExtBandsShift=0; printf("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift); } else ExtBandsShift=InpBandsShift; if(InpBandsDeviations==0.0) { ExtBandsDeviations=2.0; printf("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations); } else ExtBandsDeviations=InpBandsDeviations; //--- define buffers SetIndexBuffer(0,ExtMLBuffer); SetIndexBuffer(1,ExtTLBuffer); SetIndexBuffer(2,ExtBLBuffer); SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS); //--- set index labels PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle"); PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper"); PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower"); //--- indicator name IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); //--- indexes draw begin settings ExtPlotBegin=ExtBandsPeriod-1; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); //--- indexes shift settings PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); //--- number of digits of indicator value IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- OnInit done } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- variables int pos; //--- indexes draw begin settings, when we've recieved previous begin if(ExtPlotBegin!=ExtBandsPeriod+begin) { ExtPlotBegin=ExtBandsPeriod+begin; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin); } //--- check for bars count if(rates_total<ExtPlotBegin) return(0); //--- starting calculation if(prev_calculated>1) pos=prev_calculated-1; else pos=0; //--- main cycle for(int i=pos;i<rates_total && !IsStopped();i++) { //--- middle line ExtMLBuffer[i]=SimpleMA(i,ExtBandsPeriod,price); //--- calculate and write down StdDev ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod); //--- upper line ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- lower line ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; //--- } //---- OnCalculate done. Return new prev_calculated. return(rates_total); } //+------------------------------------------------------------------+ //| Calculate Standard Deviation | //+------------------------------------------------------------------+ double StdDev_Func(int position,const double &price[],const double &MAprice[],int period) { //--- variables double StdDev_dTmp=0.0; //--- check for position if(position<period) return(StdDev_dTmp); //--- calcualte StdDev for(int i=0;i<period;i++) StdDev_dTmp+=MathPow(price[position-i]-MAprice[position],2); StdDev_dTmp=MathSqrt(StdDev_dTmp/period); //--- return calculated value return(StdDev_dTmp); } //+------------------------------------------------------------------+ 求助 想创建一个30秒的自定义周期 求助:请教如何获取多个周期多根MACD的值 Ziheng Zhuang 2019.05.09 14:48 #1 历史数据最左边的部分没有显示很正常。。。这涉及到均线算法的问题,。。。本来就不应该显示。 niepan.syl 2019.05.10 10:36 #2 Ziheng Zhuang: 历史数据最左边的部分没有显示很正常。。。这涉及到均线算法的问题,。。。本来就不应该显示。好的 谢谢 新评论 原因: 取消 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
你好 MT5自带的布林轨在月线中 比如黄金现货 历史数据的最开始的25根K线是没有布林轨的值的 或者说没有布林轨覆盖的 这是为什么 如何能够让最初的那些K线也有画出布林轨 谢谢
下面附上布林轨公式 参数设置是26 2 附上布林轨不显示部分的截图