Download MetaTrader 5
To add comments, please log in or register
Having a great idea? Share it on the traders' Forum!
BHC
243
BHC 2011.09.20 14:44 
Indicator cannot load. Please help...?
#property copyright "M.M.Dubovikov, A.V.Kryanev, N.V.Starchenko, & bhc"
#property version   "1.00"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_level1 0.5

input int n = 5;
input int nBars = 1000;
//---- indicator buffers
double ibuffer[];

#define LOG_2_0 0.69314718055994530941723212145818 //MathLog(2.0);

int hurst;

int OnInit()
  {
   
//---- drawing settings
   ArraySetAsSeries(ibuffer,true);
   SetIndexBuffer(0,ibuffer,INDICATOR_DATA);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
   
   hurst=iCustom(NULL,0,"hurst",n,nBars);
   if(hurst==INVALID_HANDLE)
     {
      Print("hurst indicator not available!");
      return(-1);
     }
   
   return(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, j, k, kCount, nTotal, nCountedBars = 0;
   int  nInterval, nIntervalStart;
   double Delta, Xc, Yc, Sx, Sy, Sxx, Sxy,ihigh, ilow;
//---- last counted bar will be recounted
   if(nCountedBars==0) nTotal = nBars;
   if(nCountedBars>0) nTotal = Bars(NULL,0)-nCountedBars-1;
//---- main loop
   for(j=nTotal; j>=0; j--)
   {
      Sx = 0; Sy = 0; Sxx = 0; Sxy = 0;
      for(i=0; i<=n; i++)
      {
         nInterval = 1 << (n-i); //MathPow(2,n-i);
         kCount = 1 << i; //MathPow(2,i);
      //---- summarise differences of the maximum and minimum prices on an interval
         for(Delta=0, k=0; k<kCount; k++)
         {
            nIntervalStart = nInterval*k+j;
            ihigh=0.0;
            ilow=SymbolInfoDouble(NULL,SYMBOL_ASKHIGH)*2;
            for(int x=nIntervalStart;x<=nIntervalStart+nInterval;x++)
            {
               if(ihigh<high[x]) ihigh=high[x];
            }
            for(int y=nIntervalStart;y<=nIntervalStart+nInterval;y++)
            {
               if(ilow>low[y]) ilow=low[y];
            }
            Delta += ihigh-ilow;
         }
      //---- compute coordinate of variation [Xc,Yc] in double logarithmic scale
         Xc = (n-i)*LOG_2_0; //MathLog(2.0);
         Yc = MathLog(Delta);
      //---- accumulate data for finding of factors of line of regress by means of LMS (least mean squares)
         Sx += Xc; 
         Sy += Yc;
         Sxx += Xc*Xc; 
         Sxy += Xc*Yc;
      }
   //---- compute variation index (slope of the line of regress)
      ibuffer[i]=-(Sx*Sy-(n+1)*Sxy)/(Sx*Sx-(n+1)*Sxx);
  }
//--- return value of prev_calculated for next call
   return(rates_total);
  }

void OnDeinit(const int reason)
  {
   IndicatorRelease(hurst);
  }
Alexey Da
Moderator
6555
Alexey Da 2011.09.20 15:08  

Is indicator placed in MQL5\Indicators folder and compiled successfully? Try to modify your code to get an error code.

Print("hurst indicator not available! Last error is ",GetLastError());
OOP in MQL5 by Example: Processing Warning and Error Codes
  • 2010.05.26
  • KlimMalgin
  • www.mql5.com
The article describes an example of creating a class for working with the trade server return codes and all the errors that occur during the MQL-program run. Read the article, and you will learn how to work with classes and objects in MQL5. At the same time, this is a convenient tool for handling errors; and you can further change this tool according to your specific needs.
BHC
243
BHC 2011.09.20 19:38  
alexvd:

Is indicator placed in MQL5\Indicators folder and compiled successfully? Try to modify your code to get an error code.


I get error 5040. Also on compilation I get the warning 'no indicator plot defined for indicator. Assigned 1 by default'
Alexey Da
Moderator
6555
Alexey Da 2011.09.21 10:05  
Could you provide source code of hurst indicator? It should help us to reproduce your error.
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
BHC
243
BHC 2011.09.23 15:14  
alexvd:
Could you provide source code of hurst indicator? It should help us to reproduce your error.
Actually the source code is already above. The only thing I added was the print directive you gave me to read the error. But on placing the oscillator, it draws nothing and that warning still persists on compilation.
/
To add comments, please log in or register