public override void HandleNextTick(Tick t) { double emaVal = EMA.HandleNextTick(t); LRValues.Enqueue(emaVal); double[] Y = LRValues.ToArray(); LinearRegression l = new LinearRegression(); l.Model(Y); HighData.Enqueue(EMA[0] + STDEV * l.STDERR); MiddleData.Enqueue(EMA[0]); LowData.Enqueue(EMA[0] - STDEV * l.STDERR); }
public override double HandleNextTick(Tick t) { double value = double.NaN; MA.HandleNextTick(t); indicator.HandleNextTick(t); if (!MA[0].Equals(double.NaN)) { double[] MAArray = MA.ToArray(); double[] indArray = indicator.ToArray(); SortedList <double, double> tickHighs = new SortedList <double, double>(); SortedList <double, double> tickLows = new SortedList <double, double>(); SortedList <double, double> indHighs = new SortedList <double, double>(); SortedList <double, double> indLows = new SortedList <double, double>(); for (int i = 2; i < MAArray.Length; i++) { //high if (MAArray[i] < MAArray[i - 1] && MAArray[i - 1] > MAArray[i - 2]) { tickHighs.Add(i - 1, MAArray[i - 1]); } if (indArray[i] < indArray[i - 1] && indArray[i - 1] > indArray[i - 2]) { indHighs.Add(i - 1, indArray[i - 1]); } //low if (MAArray[i] > MAArray[i - 1] && MAArray[i - 1] < MAArray[i - 2]) { tickLows.Add(i - 1, MAArray[i - 1]); } if (indArray[i] > indArray[i - 1] && indArray[i - 1] < indArray[i - 2]) { indLows.Add(i - 1, indArray[i - 1]); } } if (tickHighs.Count > 0 && indHighs.Count > 0 && tickLows.Count > 0 && indLows.Count > 0) { LinearRegression lrTickHighs = new LinearRegression(); LinearRegression lrTickLows = new LinearRegression(); LinearRegression lrindkHighs = new LinearRegression(); LinearRegression lrindLows = new LinearRegression(); lrTickHighs.Model(tickHighs.Keys.ToArray(), tickHighs.Values.ToArray()); lrTickLows.Model(tickLows.Keys.ToArray(), tickLows.Values.ToArray()); lrindkHighs.Model(indHighs.Keys.ToArray(), indHighs.Values.ToArray()); lrindLows.Model(indLows.Keys.ToArray(), indLows.Values.ToArray()); if (lrTickHighs.X2 > 0 && lrindkHighs.X2 < 0) { value = 1; } else if (lrTickLows.X2 < 0 && lrindLows.X2 > 0) { value = -1; } else { value = 0; } value = lrindkHighs.Fit(indArray[0]); } } indicatorData.Enqueue(value); return(value); }