Hearst index

 

If anyone has an indicator for Hearst's indicator please send it to
I found it only on mql2 or 3
I tried to write it myself... it turned out wrong somehow... (values greater than 1)

Calculated using formula

      double Max = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, N-1, i));
      double Min = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, N-1, i));
      double R = Max - Min;
      double MA = iMA(NULL, 0, N, 0, MODE_SMA, PRICE_CLOSE, i);
      double D = 0;
         for(int a = 0; a <=N; a++)
            {
             D = D + MathPow((Close[i-a] - MA), 2);
            }
      double S = MathSqrt(D/(N-1))/*iStdDev(NULL, 0, N, 0, MODE_SMA, PRICE_CLOSE, i)*/;
      double H = MathLog(R/S)/MathLog(N/2);
      ExtMapBuffer1[i]=R;
 
Give me what you have on mql2 or 3, I'll rewrite
 
And Hearst indicators are counted in different ways. I have heard of 3 ways. On the risk manager forum.
 
Integer писал (а):
Give me what you have on mql2 or 3, I'll rewrite

here is the link https://www.mql5.com/ru/forum/50458
 
favoritefx писал (а):
And Hearst ratios are counted differently. I've heard of 3 ways, on the risk manager forum.


I understand the formula to be

H = MathLog(R/S)/MathLog(N/2)

 
Oasis писал (а):
Integer wrote (a):
Give me what you have on mql2 or 3, I'll rewrite

here is the link https://www.mql5.com/ru/forum/50458





#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Yellow
extern int PeriodHerst=24,PeriodA=100;
double ExtMapBuffer1[];double ExtMapBuffer2[];
int init(){
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexDrawBegin(0,PeriodHerst+PeriodA);
   SetIndexDrawBegin(1,PeriodHerst+PeriodA);   
   return(0);
}
int start(){
   int    limit=Bars-IndicatorCounted();
   for(int i=limit-1;i>=0;i--){
      int MaxH=Highest(NULL,0,MODE_HIGH,PeriodHerst,i);
      int MinL=Lowest(NULL,0,MODE_LOW,PeriodHerst,i);  
      double Average=iMA(NULL,0,PeriodA,0,0,0,i);
      double swap=0;
         for(int j=0;j<PeriodA;j++){
            swap=swap+MathPow(Open[j+i]-Average,2);
            swap=swap+MathPow(High[j+i]-Average,2);
            swap=swap+MathPow(Low[j+i]-Average,2);
            swap=swap+MathPow(Close[j+i]-Average,2);            
         }       
      double Deviation=MathSqrt(swap/((PeriodA-1)*PeriodA));
      ExtMapBuffer1[i]=(High[MaxH]-Low[MinL])/Deviation;
        for(j=0;j<PeriodA;j++){
           swap=swap+ExtMapBuffer1[i+j];
        }
     ExtMapBuffer2[i]=swap/PeriodA;
   }
   return(0);
}

Just what it is, but judging by the PeriodHerst variable, it's something to do with Hearst

 
We'll be right there... sorting it out ))))
Thanks for the code, Dimitri.
 

It's some kind of wrong indicator. The Hurst constant is supposed to fluctuate around 0.5. NOT more than 1 and not less than 0. This is somewhat different.

 

The good thing is that everyone knows the Hearst value area. The only bad thing is that nobody looks inside the code. Can someone explain me what value is calculated in this indicator where it should be calculated by sko ?

 
Oasis, I myself was inspired by the discussion https://www.mql5.com/ru/forum/50458 and tried to write it. It's not very expressive or correct. The main problem is how to calculate S, or how it can be plausibly substituted. After all, we are working not with ticks, but with bars. And calculations strictly according to definitions are hardly good here... Anyway, I am sending you my preliminary and unsatisfactory (pardon the pun) result. Perhaps someone will find it useful.

 
#property copyright "Черный Кот"
#property link      ""
 
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_color1 Red
 
 
extern int nBars=1000; 
extern int PerM=1;     
 
//поля в массиве Rates
#define RATE_TIME  0 
#define RATE_OPEN  1
#define RATE_LOW   2
#define RATE_HIGН  3
#define RATE_CLOS  4
#define RATE_VOL   5
 
 
 
 
//---- buffers
double HurstBuf[];   //буфер индикатора
double RateM[][6];   //массив баров младшего таймфрейма, по которому вычисляется Херст
int nM;              //число баров младшего таймфрейма, доступных в истории
 
 
bool CriticalError=false; //флаг критической ошибки устанавливается если не удалось
//загрузить младший таймфрейм
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//инициализируем буфер
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,HurstBuf);
   
//получаем доступ к младшему таймфрейму
   CriticalError=false;
   for(int i=0; i<10; i++) //делаем 10 попыток
   {
      nM=ArrayCopyRates(RateM, NULL, PerM);
      if(GetLastError()==0) break;
      Sleep(5000);
   }         
   if(i==10)
   {
      Print("Cannot load lower timeframe");
      CriticalError=true;
   }   
   Print("nM=",nM);  
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
 
 
 
 
int start()
{
   if(CriticalError) return (0);
   int counted_bars=IndicatorCounted();
//   for(int i=1; i<nBars; i++) HurstBuf[i]=0.5;
   for(int i=1; i<nBars; i++)//считаем с первого бара
   {
      double avg=(High[i]+Low[i])/2; //среднее в баре
      double R=High[i]-Low[i];       //размах бара       
            
      //находим последний бар младшего таймфрейма, принадлежащий i-му бару текущего
      datetime t=Time[i] + Period()*60; //время закрытия i-го бара в секундах
//      Print("Bar ",i," Time=",TimeToStr(Time[i]));
      for(int j=0; j<nM; j++) //ищем во всей доступной истории
      {
//         Print("*****Bar ",j," Time=",TimeToStr(RateM[j][RATE_TIME]));  
         if(RateM[j][RATE_TIME]<=t) break;
      }           
      if(j==nM) return (0); //история по младшему таймфрейму кончилась и считать больше нечего
                        
      //сейчас j указывает на искомый последний бар в младшем таймфрейме
      //вычисляем СКО. Как его считать, это самый непонятный во всём этом момент
      int N=0;
      double s=0;
      while(Time[i]<=RateM[N+j][RATE_TIME]) //считаем пока находимся в пределах i-го бара
      {
         //double m=avg - (RateM[N+j][RATE_HIGН]+RateM[N+j][RATE_LOW ])/2;
         double m=RateM[N+j][RATE_HIG]-RateM[N+j][RATE_LOW ];
         s+=m*m;
         
//         s += (avg - RateM[N+j][RATE_HIGН])*(avg - RateM[N+j][RATE_HIGН]);
//         s += (avg - RateM[N+j][RATE_LOW ])*(avg - RateM[N+j][RATE_LOW ]);         
         N++;
      }                    
      double S=MathSqrt(s/N);
      
      double h=MathLog(R/S)/MathLog(N); //вычисляем показатель Херста
//      Print("Lo=", Low[i], " Hi=",High[i], " t=",TimeToStr(Time[i]), " h=",h, " R=",R, " S=", S, " avg=", avg);                  
      HurstBuf[i]=h; //загоняем его в буфер      
   }   
//   CriticalError=true;
   return(0);
}
//+------------------------------------------------------------------+
 

Hi Eugene !

I think your idea to use the low low to calculate Hearst on the high is very correct. But you calculate the SCO incorrectly. Why do you have the difference there (High - Low)? The RMS is the sum of the squares of the deviations of the series values from the mean. What is commented out below is much more like RMS.

Also, Hurst is not a ratio of logarithms, but the slope of a linear regression which is plotted against those logarithms. You don't have to build the regression. Just consider the additive term in the equation Log(R/S) = H*Log(N/2) +C in another way.