public double getHurst(TimeFrame timeframe, double hurstPeriod) { double m = 0; double R = 0; double S = 0; double a = 0.5; List<double> Y = new List<double>(); QuoteStruct tempQS = new QuoteStruct(); List<QuoteStruct> tempQouteList = new List<QuoteStruct>(); switch (timeframe) { case TimeFrame.M1: tempQouteList = M1ListQS; break; case TimeFrame.M5: tempQouteList = M5ListQS; break; case TimeFrame.M15: tempQouteList = M15ListQS; break; case TimeFrame.M30: tempQouteList = M30ListQS; break; case TimeFrame.H1: tempQouteList = H1ListQS; break; case TimeFrame.H4: tempQouteList = H4ListQS; break; case TimeFrame.D1: tempQouteList = D1ListQS; break; } for (int i = 0; i < hurstPeriod - 1; i++) { tempQS = tempQouteList.ElementAt(i); m += tempQS.Close; } m = m / hurstPeriod; for (int i = 0; i < hurstPeriod - 1; i++) { tempQS = tempQouteList.ElementAt(i); Y.Add(tempQS.Close - m); S = Math.Pow(tempQS.Close - m, 2); } R = Y.Max() - Y.Min(); S = Math.Sqrt(S / (hurstPeriod - 1)); return (Math.Log(R / S) / Math.Log(hurstPeriod * a)); }
/// <summary> /// Background worker for generate time series /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorkerSeries_DoWork(object sender, DoWorkEventArgs e) { FractalClass fractalClass = new FractalClass(); List<QuoteStruct> tempList = new List<QuoteStruct>(); QuoteStruct tempQuoute = new QuoteStruct(); List<double> close = new List<double>(); MyDBDataSetTableAdapters.ratesTableAdapter tbAdapter = new MyDBDataSetTableAdapters.ratesTableAdapter(); //baseDataSetTableAdapters.ratesTableAdapter tbAdapter = new baseDataSetTableAdapters.ratesTableAdapter(); double LastNum=1.42990; int SeriesNo; for (int k = 0; k < days_for_generate; k++) { SeriesNo = 1; for (int n = 0; n < 10; n++) { for (int i = 1; i < time_series_count; i++) { //if (k>0) LastNum=Double.Parse(tbAdapter.LastClose(i).ToString()); fractalClass.CreateFractal(FractalClass.TimeFrame.H1, 24, (n + 1) / 100, 0, 24, 0, 6, LastNum, (double)i / atr_coefficient); tempList = fractalClass.H1ListQS; // Set colors bars for (int j = 0; j < tempList.Count; j++) { tempQuoute = tempList.ElementAt(j); //if (tempQuoute.High<1.46&&tempQuoute.Low>1.2) tbAdapter.Insert(0, "EUR/USD", SeriesNo, (float)tempQuoute.Open, (float)tempQuoute.High, (float)tempQuoute.Low, (float)tempQuoute.Close, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); } SeriesNo++; } } backgroundWorkerSeries.ReportProgress(k); } }
public void FillQouteStruct(TimeFrame timeframe, double baseVal) { double iVar; double maxVal = 0; double minVal = Ticks.ElementAt(0); bool nextStep = false; QuoteStruct tempQS = new QuoteStruct(); List<QuoteStruct> tempQouteList = new List<QuoteStruct>(); tempQS.Open = Ticks.ElementAt(0); for (int i = 0; i < Ticks.Count; i++) { if (nextStep) { tempQS.Open = Ticks.ElementAt(i); minVal = Ticks.ElementAt(i); maxVal = 0; nextStep = false; } if (Ticks.ElementAt(i) > maxVal) maxVal = Ticks.ElementAt(i); if (minVal > Ticks.ElementAt(i)) minVal = Ticks.ElementAt(i); iVar = Double.Parse(i.ToString()); if (iVar % baseVal == 0) { tempQS.High = maxVal; tempQS.Low = minVal; tempQS.Close = Ticks.ElementAt(i); tempQouteList.Add(tempQS); nextStep = true; } } switch (timeframe) { case TimeFrame.M1: M1ListQS = tempQouteList; break; case TimeFrame.M5: M5ListQS = tempQouteList; break; case TimeFrame.M15: M15ListQS = tempQouteList; break; case TimeFrame.M30: M30ListQS = tempQouteList; break; case TimeFrame.H1: H1ListQS = tempQouteList; break; case TimeFrame.H4: H4ListQS = tempQouteList; break; case TimeFrame.D1: D1ListQS = tempQouteList; break; } }