简体   繁体   English

任何MQL4程序员? 此代码有什么问题?

[英]Any MQL4 programmers? What is wrong with this code?

When I try to divide the two doubles in a buffer my indicator blacks out, and the values go extreme in the second window -90000000 and 90000000 当我尝试在缓冲区中将两个双精度数相除时,指示器熄灭,并且第二个窗口中的值达到极值-90000000和90000000

    #property indicator_separate_window // Îòîáðàæåíèå â îòäåëüíîì îêíå
    #property indicator_buffers 3       // Êîëè÷åñòâî áóôåðîâ
    #property indicator_color1 Red     // Öâåò ïåðâîé ëèíèè
    #property indicator_color2 Blue     // Öâåò âòîðîé ëèíèè
    #property indicator_color3 Green

    double FillBuffer[];
    double DBuffer[];
    double AverageBuffer[];

    double H,L;
    double point=Point();

   int init()                          // Ñïåöèàëüíàÿ ôóíêöèÿ init()
   {  
      int period =  _Period;  
      string symbol =  Symbol();
      int digits =  _Digits ;   
      point =  _Point ;

     if(digits == 5 || digits == 3) { digits = digits - 1 ; point = point * 10 ; } 


     SetIndexBuffer(0,DBuffer);   
     SetIndexBuffer(1,FillBuffer);
     SetIndexBuffer(2,AverageBuffer);    
     SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);
     SetIndexLabel(0, "ADR");


     return(INIT_SUCCEEDED);                       
     }

     int start()
     {


     int i, limit, counted_bars;

     counted_bars = IndicatorCounted();
     //---- check for possible errors
     if (counted_bars<0) return(-1);
     //---- last counted bar will be recounted
     if (counted_bars>0) counted_bars--;
     limit = Bars - counted_bars;

     for (i = limit; i >= 0; i--)
     {
     double dbuff= iHigh(NULL,0,i)- iLow(NULL,0,i);
     double D0  = iHigh(NULL,0,i+1)- iLow(NULL,0,i+1);
     double D1  = iHigh(NULL,0,i+2)- iLow(NULL,0,i+2);
     double D2  = iHigh(NULL,0,i+3)- iLow(NULL,0,i+3);
     double D3  = iHigh(NULL,0,i+4)- iLow(NULL,0,i+4);
     double D4  = iHigh(NULL,0,i+5)- iLow(NULL,0,i+5);
     double Average = ((D0+D1+D2+D3+D4)/5)/point;
     FillBuffer[i]=dbuff/Average;

     }

     return(0);

When I try to divide the two values in FillBuffer[] my indicator blacks out. 当我尝试对FillBuffer[]的两个值进行除法时,指示器熄灭。 But if I just have either the dbuff or Average in the buffer it will show lines but I want the percentage one is of the other to be printed. 但是,如果缓冲区中只有dbuffAverage ,它将显示多行,但我希望打印出一个百分比。

There is not much wrong with the code, but it does not paint the line: 该代码并没有什么大不了,但是它并没有画线:

Some polishing may help, but the core logic of the MQL4 Custom Indicator is forgotten in the code. 一些改进可能会有所帮助,但是代码中遗忘了MQL4自定义指示器的核心逻辑。 If one does not assign a way, how to plot ( paint ) the line on screen, the GUI will remain "blacked-out" even though the values may have gotten calculated. 如果未分配一种方法,即如何在屏幕上绘制(绘制)线条,即使可能已计算出值,GUI也将保持“涂黑”状态。


Performance warning: 效果警告:

Custom Indicators ( all Custom Indicators ) share one common solo-thread ( !! ), so proper performance tuning is warmly recommended in this type of MQL4-code-execution blocks. 自定义指标( 所有自定义指标)共享一个公共的独线程( !! ),因此在这种类型的MQL4代码执行块中强烈建议进行适当的性能调整。

Some further acceleration might be achieved by reducing / avoiding all the repetitive re-averaging via a sliding-window implementation replacement. 通过减少/避免通过滑动窗口实现替换的所有重复性重新平均,可以实现进一步的加速。 While this is not so risky at 5-BARs deep re-processing, for deeper TimeSeries convolutions, the effect is significant and impressive in Strategy Tester accelerated mode of computing's run-times ( getting down to minutes instead of hours ). 尽管在5-BAR深度重新处理时这没有那么大的风险,但是对于更深的TimeSeries卷积,在Strategy Tester加速的计算运行时间模式(减少到几分钟而不是几小时)中,效果显着且令人印象深刻。 Worth one's time and efforts. 值得付出时间和精力。

#property indicator_separate_window
#property indicator_buffers         3
#property indicator_color1          Red
#property indicator_color2          Blue
#property indicator_color3          Green

      double    FillBuffer[];
      double       DBuffer[];                         // NEVER FILLED IN
      double AverageBuffer[];                         // NEVER FILLED IN

      double point = Point();

int   init()
{     int    period =  _Period;                       // NEVER CONSUMED    
      string symbol =   Symbol();                     // NEVER CONSUMED
      int    digits =  _Digits ;                      // LOCAL SCOPE ONLY VISIBLE INSIDE init(){...}
             point  =  _Point ;

      if (  digits == 5 || digits == 3 ) { digits -=  1;
                                           point  *= 10;
                                           }

      SetIndexBuffer( 0,       DBuffer );
      SetIndexBuffer( 1,    FillBuffer );             // 1: ASSIGNED, BUT NEVER SET TO HAVE ANY { DRAW_LINE | DRAW_ ... } GUI OUTPUT
      SetIndexBuffer( 2, AverageBuffer );             // 2: ASSIGNED, BUT NEVER SET TO HAVE ANY { DRAW_LINE | DRAW_ ... } GUI OUTPUT
      SetIndexStyle ( 0, DRAW_LINE, STYLE_SOLID, 1 ); // 0: SET AS DRAW_LINE ( BUT NEVER FILLED IN WITH DATA )
      SetIndexLabel(  0, "ADR" );

      return( INIT_SUCCEEDED );
   }

int   start()
{     int i, limit, counted_bars;
      counted_bars = IndicatorCounted();
//----check for possible errors
      if ( counted_bars < 0 ) return( -1 );

//----last counted bar will be recounted
      if ( counted_bars > 0 ) counted_bars--;

      limit = ( Bars - 5 ) - counted_bars;            // AVOID 1st 5 BARS,
      int   i0, i1, i2, i3, i4, i5;                   // WHERE (i+5) WILL OVERFLOW THE TIMESERIES LEFT EDGE
      for ( i  = limit,
            i1 = i + 1,
            i2 = i + 2,
            i3 = i + 3,
            i4 = i + 4,
            i5 = i + 5; i >= 0; i--,
                                i1--,
                                i2--,
                                i3--,
                                i4--,
                                i5--
                                )
      {     FillBuffer[i]  = (   High[i]
                                - Low[i]
                                )
                           / ( ( High[i1] + High[i2] + High[i3] + High[i4] + High[i5] )
                             - (  Low[i1] +  Low[i2] +  Low[i3] +  Low[i4] +  Low[i5] )
                               )
                           / 5.
                           / point;

         /* double dbuff   = iHigh( NULL, 0, i   ) - iLow( NULL, 0, i   );
            double D0      = iHigh( NULL, 0, i+1 ) - iLow( NULL, 0, i+1 );
            double D1      = iHigh( NULL, 0, i+2 ) - iLow( NULL, 0, i+2 );
            double D2      = iHigh( NULL, 0, i+3 ) - iLow( NULL, 0, i+3 );
            double D3      = iHigh( NULL, 0, i+4 ) - iLow( NULL, 0, i+4 );
            double D4      = iHigh( NULL, 0, i+5 ) - iLow( NULL, 0, i+5 );
            double Average = ( ( D0 + D1 + D2 + D3 + D4 ) / 5 ) / point;
            FillBuffer[i]  = dbuff / Average;
            */
      }
      return( 0 );
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM