You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I downloaded a program that calculates Hurst index. I have created a file with bar opening prices in the script.
I opened the file and the program calculated the Hurst index. But whatever sample I select the program always shows indicator values close to 1. But it does not fit the theory, does it? That is, the reading should vary from 0 to 1 for different samples? But in this program this parameter is glued to 1 :o(. In general, I'm glad that the ready calculation functions are available on the site. And now I'm afraid to use them to calculate something.
I've got this coefficient so far within the range 0.21-0.39. I don't know why :o(.
Here is my code of the script, which I based on your code:
//+------------------------------------------------------------------+ //| Herst.mq4 | //| Copyright © 2006, MetaQuotes Software Corp. | //| https://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, MetaQuotes Software Corp." #property link "https://www.metaquotes.net" #property show_inputs extern int start_bar=500; extern int end_bar=0; //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { double viborka[10]; int size_of_array,i; size_of_array=start_bar-end_bar+1; ArrayResize(viborka, size_of_array); for(i=size_of_array-1;i>=0;i--) viborka[i]=Open[i+end_bar]; double S_A=srednee_arifmeticheskoe(viborka); Print("Среднее арифметическое выборки = ",DoubleToStr(S_A,8)); double disp=dispercia(viborka,S_A); Print("Дисперсия выборки = ",DoubleToStr(disp,8)); double S=CKO(disp); Print("СКО выборки (размах) = ",DoubleToStr(S,8)); double pMin=Low[Lowest(NULL,0,MODE_LOW,size_of_array,end_bar)]; double pMax=High[Highest(NULL,0,MODE_HIGH,size_of_array,end_bar)]; double R=pMax-pMin; Print("pMin = ",pMin," pMax = ",pMax, " R = ",R); double Hrst; if( (R>0)&&(S>0)) Hrst = MathLog(R/S)/MathLog(size_of_array*0.5); Print("Хёрст = ",DoubleToStr(Hrst ,8)); return(0); } //+------------------------------------------------------------------+ //функция для расчёта СКО double CKO(double disper) { double sko=MathPow(disper,0.5); return(sko); } //функция для расчёта дисперсии double dispercia(double data[], double centr) { int k,size; double disper=0; size=ArraySize(data); for(k=size-1;k>=0;k--) disper=disper+MathPow((data[k]-centr),2); if(size>1) disper=disper/(size-1); return(disper); } //функция для подсчёта среднего арифметического значения по массиву double srednee_arifmeticheskoe(double data[]) { int k,size; double sr_arifm=0; size=ArraySize(data); for(k=size-1;k>=0;k--) sr_arifm=sr_arifm+data[k]; sr_arifm=sr_arifm/size; return(sr_arifm); }Vladislav, maybe you can just take a look and tell me where to tweak in order to calculate the coefficient correctly? After all, according to the theory all calculations are elementary and I don't even know where my error is :o(
And then such a number of function calls on an algorithm which is already not much lightened by calculations..... IMHO it will slow down considerably. (The function call is the longest procedure, then comes the floating point division operation).
What's wrong with the standard algorithm for calculating standard deviation? It is available, but the forecast takes the value of a muving on the corresponding bar - take what you need, this is it and no function calls. You just run a loop through an array and squared the differences between the forecast price on a given bar and the real price, then square root it once - that's it.
Good luck and good luck with trends.
http://forex.ua/forum/viewtopic.php?t=1634&postdays=0&postorder=asc&start=50
There was a short term comparison of FA and TA forecasts here (after some flam in the thread just got fed up).
http://forex.ua/forum/viewtopic.php?t=1780
Thanks for the links! Have a read. Very informative! It once again confirmed to me that I correctly understand the essence of your strategy. I have already started to program something in this direction myself. I've already written above about the current problems on the agenda. But even the first calculation results are very impressive! Indeed, until you try it yourself you can not understand why things really happen the way you say! This is what makes your strategy so unpopular with the majority of traders. It is much more attractive to look at beautiful multi-coloured charts of different oscillators ;o) and read different paid analysts, than to base your Forex trading strategy on knowledge accumulated by people for a long time. Although, in principle, as long as this state of affairs remains, it will be possible to earn good money on Forex!
:).
Good luck and good trends.
What's wrong with the standard algorithm for calculating standard deviation? It is available, but it takes the value of a muving on the corresponding bar as a prognosis - take what you need, this is it and no function calls. Just run a loop through the array and take the squares of the differences between the forecast price on the given bar and the real one, then take the square root once - that's it.
In this example I've used sample arithmetic mean as the centr variable.
Also yesterday I tried setting a linear regression line as this variable. So then we get that S=SCO of linear regression errors. But for some reason the result didn't impress me either :o(.
Here is the code of the script, in which we take a linear regression line as a forecast. Moreover, the current EURUSD trend fits this very well.
//+------------------------------------------------------------------+ //| Herst.mq4 | //| Copyright © 2006, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property show_inputs extern int start_bar=500; extern int end_bar=0; //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { double viborka[10],oshibki_lin_reg[10]; int size_of_array,i; size_of_array=start_bar-end_bar+1; ArrayResize(viborka, size_of_array); ArrayResize(oshibki_lin_reg, size_of_array); for(i=size_of_array-1;i>=0;i--) viborka[i]=Open[i+end_bar]; double S_A_viborki=srednee_arifmeticheskoe(viborka); Print("Среднее арифметическое выборки = ",DoubleToStr(S_A_viborki,8)); //-----Расчёт коэффициента a уравнения линейной регрессии double sred_znach_i=(size_of_array-1)/2.0; //среднее значение по оси индекса double a_lin_regres=0;//коэффициент a линейной регрессии double buffer=0; for(i=size_of_array-1;i>=0;i--) { a_lin_regres=a_lin_regres+(i-sred_znach_i)*(viborka[i]-S_A_viborki); buffer=buffer+MathPow((i-sred_znach_i),2); } a_lin_regres=a_lin_regres/buffer; Print("a_lin_regres = ",DoubleToStr(a_lin_regres,8)); //-----Расчёт коэффициента b уравнения линейной регрессии double b_lin_regres=S_A_viborki-a_lin_regres*sred_znach_i; Print("b_lin_regres = ",DoubleToStr(b_lin_regres,8)); //-----Расчёт ошибок линейной регрессии for(i=size_of_array-1;i>=0;i--) oshibki_lin_reg[i]=viborka[i]-(a_lin_regres*i+b_lin_regres); double S_A_oshibok;//среднее значение ошибок линейной регрессии S_A_oshibok=srednee_arifmeticheskoe(oshibki_lin_reg); Print("Среднее значение ошибок = ",DoubleToStr(S_A_oshibok,8)); double disp_oshibok=dispercia_oshibok(oshibki_lin_reg,S_A_oshibok); Print("Дисперсия ошибок= ",DoubleToStr(disp_oshibok,8)); double S=CKO(disp_oshibok); Print("S= ",DoubleToStr(S,8)); double pMin=0; double pMax=0; for(i=size_of_array-1;i>=0;i--) { if(oshibki_lin_reg[i]<pMin) pMin=oshibki_lin_reg[i]; if(oshibki_lin_reg[i]>pMax) pMax=oshibki_lin_reg[i]; } double R=pMax-pMin; Print("pMin = ",pMin," pMax = ",pMax, " R = ",R); double Hrst; Hrst = MathLog(R/S)/MathLog(size_of_array*0.5); Print("Хёрст = ",DoubleToStr(Hrst ,8)); return(0); } //+------------------------------------------------------------------+ //функция для расчёта дисперсии ошибок double dispercia_oshibok(double data[], double centr) { int k,size; double disper=0; size=ArraySize(data); for(k=size-1;k>=0;k--) disper=disper+MathPow((data[k]-centr),2); if(size>1) disper=disper/(size-2); return(disper); } //функция для расчёта СКО double CKO(double disper) { double sko=MathPow(disper,0.5); return(sko); } //функция для подсчёта среднего арифметического значения по массиву double srednee_arifmeticheskoe(double data[]) { int k,size; double sr_arifm=0; size=ArraySize(data); for(k=size-1;k>=0;k--) sr_arifm=sr_arifm+data[k]; sr_arifm=sr_arifm/size; return(sr_arifm); }Let's take the H1 period on EURUSD. We take a sample of 500 bars Hearst's coefficient = 0.26
300 bars - 0.31, 100 bars - 0.39, 30 bars - 0.51. I don't understand why :o(.
We will try your recommended muving. Although i do not know yet why the results will fundamentally differ from what i have.
//+------------------------------------------------------------------+ //| Herst_lin_reg.mq4 | //| Copyright © 2006, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property show_inputs extern int start_bar=800; extern int end_bar=570; //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { double viborka[10],oshibki_lin_reg[10],data_for_drawing[10]; int size_of_array,i; size_of_array=start_bar-end_bar+1; ArrayResize(viborka, size_of_array); ArrayResize(oshibki_lin_reg, size_of_array); ArrayResize(data_for_drawing, size_of_array); for(i=size_of_array-1;i>=0;i--) viborka[i]=Open[i+end_bar]; double S_A_viborki=srednee_arifmeticheskoe(viborka); Print("Среднее арифметическое выборки = ",DoubleToStr(S_A_viborki,8)); //-----Расчёт коэффициента a уравнения линейной регрессии double sred_znach_i=(size_of_array-1)/2.0; //среднее значение по оси индекса double a_lin_regres=0;//коэффициент a линейной регрессии double buffer=0; for(i=size_of_array-1;i>=0;i--) { a_lin_regres=a_lin_regres+(i-sred_znach_i)*(viborka[i]-S_A_viborki); buffer=buffer+MathPow((i-sred_znach_i),2); } a_lin_regres=a_lin_regres/buffer; Print("a_lin_regres = ",DoubleToStr(a_lin_regres,8)); //-----Расчёт коэффициента b уравнения линейной регрессии double b_lin_regres=S_A_viborki-a_lin_regres*sred_znach_i; Print("b_lin_regres = ",DoubleToStr(b_lin_regres,8)); for(i=size_of_array-1;i>=0;i--) data_for_drawing[i]=a_lin_regres*i+b_lin_regres; linregres_grafic_c(0,data_for_drawing,end_bar); //-----Расчёт ошибок линейной регрессии for(i=size_of_array-1;i>=0;i--) oshibki_lin_reg[i]=viborka[i]-(a_lin_regres*i+b_lin_regres); double S_A_oshibok;//среднее значение ошибок линейной регрессии S_A_oshibok=srednee_arifmeticheskoe(oshibki_lin_reg); Print("Среднее значение ошибок = ",DoubleToStr(S_A_oshibok,8)); double disp_oshibok=dispercia_oshibok(oshibki_lin_reg,S_A_oshibok); Print("Дисперсия ошибок= ",DoubleToStr(disp_oshibok,8)); double S=CKO(disp_oshibok); Print("S= ",DoubleToStr(S,8)); double pMin=Low[Lowest(NULL,0,MODE_LOW,size_of_array,end_bar)]; double pMax=High[Highest(NULL,0,MODE_HIGH,size_of_array,end_bar)]; double R=pMax-pMin; Print("pMin = ",pMin," pMax = ",pMax, " R = ",R); double Hrst; Hrst = MathLog(R/S)/MathLog(size_of_array*0.5); Print("Хёрст = ",DoubleToStr(Hrst ,8)); Comment("Хёрст = ",DoubleToStr(Hrst ,8)); return(0); } //+------------------------------------------------------------------+ //функция для расчёта дисперсии ошибок double dispercia_oshibok(double data[], double centr) { int k,size; double disper=0; size=ArraySize(data); for(k=size-1;k>=0;k--) disper=disper+MathPow((data[k]-centr),2); if(size>1) disper=disper/(size-2); return(disper); } //функция для расчёта СКО double CKO(double disper) { double sko=MathPow(disper,0.5); return(sko); } //функция для подсчёта среднего арифметического значения по массиву double srednee_arifmeticheskoe(double data[]) { int k,size; double sr_arifm=0; size=ArraySize(data); for(k=size-1;k>=0;k--) sr_arifm=sr_arifm+data[k]; sr_arifm=sr_arifm/size; return(sr_arifm); } //функция рисования канала линейной регрессии int linregres_grafic_c(int window_number, double data[], int ended_bar) { int deletedArrows,k,size; string line_name; //очистка предыдущего рисунка deletedArrows=ObjectsDeleteAll(window_number,OBJ_TREND); //находим размер массива size=ArraySize(data); //рисуем центральную линию линейной регрессии for(k=size-1;k>=1;k--) { line_name="line_lin_reg"+k; ObjectCreate(line_name,OBJ_TREND,window_number,Time[k+ended_bar],data[k],Time[k+ended_bar-1],data[k-1]); ObjectSet(line_name,OBJPROP_COLOR,Yellow); ObjectSet(line_name,OBJPROP_STYLE,DRAW_LINE); ObjectSet(line_name,OBJPROP_WIDTH,2); ObjectSet(line_name,OBJPROP_BACK,true); ObjectSet(line_name,OBJPROP_RAY,false); } //рисуем проекцию центральной линии линейной регрессии line_name="line_lin_reg_proec"; ObjectCreate(line_name,OBJ_TREND,window_number,Time[size-1+ended_bar],data[size-1],Time[ended_bar],data[0]); ObjectSet(line_name,OBJPROP_COLOR,Red); ObjectSet(line_name,OBJPROP_STYLE,DRAW_LINE); ObjectSet(line_name,OBJPROP_WIDTH,1); ObjectSet(line_name,OBJPROP_BACK,false); ObjectSet(line_name,OBJPROP_RAY,true); return(0); }Here's the link where the screenshots are located https://c.mql5.com/mql4/forum/2006/05/Herst.zip
At first I tried to upload these picture files to the site, so it would be convenient to look them in the theme itself, but for some reason these gif files on www.mql4.com site after the engine change persistently do not want to be inserted :o(. Never mind the good thing that at least zip uploaded.
A brief explanation of the script. The script draws a thick yellow line of the linear regression channel in the chart and at the same time it plots the projection of the channel in future with a thin red line.
Judging by the screenshots, I must be right in my calculations :o). Although I will need to double-check in the future.
PS: Vladislav, I think the Hurst index calculation by muving is a bit dubious, because it is unknown which value of the averaging period should be taken. I assume that this value for each particular calculation should somehow change depending on the number of tochets. That's why I've settled on a linear regression channel for now.
This is what I understood (probably incorrectly).
//+------------------------------------------------------------------+ //| SHI_Channel.mq4 | //| Copyright © 2004, Shurka & Kevin | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, Shurka & Kevin" #property link "" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red double ExtMapBuffer1[]; //---- input parameters extern int AllBars=240; extern int BarsForFract=0; int CurrentBar=0; double Step=0; int B1=-1,B2=-1; int UpDown=0; double P1=0,P2=0,PP=0; int i=0,AB=300,BFF=0; int ishift=0; double iprice=0; datetime T1,T2; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,164); SetIndexBuffer(0,ExtMapBuffer1); SetIndexEmptyValue(0,0.0); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } void DelObj() { ObjectDelete("TL1"); ObjectDelete("TL2"); ObjectDelete("MIDL"); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- if ((AllBars==0) || (Bars<AllBars)) AB=Bars; else AB=AllBars; //AB-количество обсчитываемых баров if (BarsForFract>0) BFF=BarsForFract; else { switch (Period()) { case 1: BFF=12; break; case 5: BFF=48; break; case 15: BFF=24; break; case 30: BFF=24; break; case 60: BFF=12; break; case 240: BFF=15; break; case 1440: BFF=10; break; case 10080: BFF=6; break; default: DelObj(); return(-1); break; } } CurrentBar=2; //считаем с третьего бара, чтобы фрактал "закрепился B1=-1; B2=-1; UpDown=0; while(((B1==-1) || (B2==-1)) && (CurrentBar<AB)) { //UpDown=1 значит первый фрактал найден сверху, UpDown=-1 значит первый фрактал //найден снизу, UpDown=0 значит фрактал ещё не найден. //В1 и В2 - номера баров с фракталами, через них строим опорную линию. //Р1 и Р2 - соответственно цены через которые будем линию проводить if((UpDown<1) && (CurrentBar==Lowest(Symbol(),Period(),MODE_LOW,BFF*2+1,CurrentBar-BFF))) { if(UpDown==0) { UpDown=-1; B1=CurrentBar; P1=Low[B1]; } else { B2=CurrentBar; P2=Low[B2];} } if((UpDown>-1) && (CurrentBar==Highest(Symbol(),Period(),MODE_HIGH,BFF*2+1,CurrentBar-BFF))) { if(UpDown==0) { UpDown=1; B1=CurrentBar; P1=High[B1]; } else { B2=CurrentBar; P2=High[B2]; } } CurrentBar++; } if((B1==-1) || (B2==-1)) {DelObj(); return(-1);} // Значит не нашли фракталов среди 300 баров 8-) Step=(P2-P1)/(B2-B1);//Вычислили шаг, если он положительный, то канал нисходящий P1=P1-B1*Step; B1=0;//переставляем цену и первый бар к нулю //А теперь опорную точку противоположной линии канала. ishift=0; iprice=0; if(UpDown==1) { PP=Low[2]-2*Step; for(i=3;i<=B2;i++) { if(Low[i]<PP+Step*i) { PP=Low[i]-i*Step; } } if(Low[0]<PP) {ishift=0; iprice=PP;} if(Low[1]<PP+Step) {ishift=1; iprice=PP+Step;} if(High[0]>P1) {ishift=0; iprice=P1;} if(High[1]>P1+Step) {ishift=1; iprice=P1+Step;} } else { PP=High[2]-2*Step; for(i=3;i<=B2;i++) { if(High[i]>PP+Step*i) { PP=High[i]-i*Step;} } if(Low[0]<P1) {ishift=0; iprice=P1;} if(Low[1]<P1+Step) {ishift=1; iprice=P1+Step;} if(High[0]>PP) {ishift=0; iprice=PP;} if(High[1]>PP+Step) {ishift=1; iprice=PP+Step;} } //Теперь переставим конечную цену и бар на АВ, чтобы линии канала рисовались подлиннее P2=P1+AB*Step; T1=Time[B1]; T2=Time[AB]; //Если не было пересечения канала, то 0, иначе ставим псису. if(iprice!=0) ExtMapBuffer1[ishift]=iprice; DelObj(); ObjectCreate("TL1",OBJ_TREND,0,T2,PP+Step*AB,T1,PP); ObjectSet("TL1",OBJPROP_COLOR,Lime); ObjectSet("TL1",OBJPROP_WIDTH,2); ObjectSet("TL1",OBJPROP_STYLE,STYLE_SOLID); ObjectCreate("TL2",OBJ_TREND,0,T2,P2,T1,P1); ObjectSet("TL2",OBJPROP_COLOR,Lime); ObjectSet("TL2",OBJPROP_WIDTH,2); ObjectSet("TL2",OBJPROP_STYLE,STYLE_SOLID); ObjectCreate("MIDL",OBJ_TREND,0,T2,(P2+PP+Step*AB)/2,T1,(P1+PP)/2); ObjectSet("MIDL",OBJPROP_COLOR,Lime); ObjectSet("MIDL",OBJPROP_WIDTH,1); ObjectSet("MIDL",OBJPROP_STYLE,STYLE_DOT); // Comment(" Channel size = ", DoubleToStr(MathAbs(PP - P1)/Point,0), " Slope = ", DoubleToStr(-Step/Point, 2)); //---- //---- return(0); } //+------------------------------------------------------------------+This indicator is taken from this strategy
http://fxovereasy.50webs.com/Example1.html
You can download the necessary indicators for this strategy for MT4 from the website.
http://fxovereasy.50webs.com/Indicators.html
Everything seems to make sense at first glance. There is no other strategy description ;o).