public Example GenerateGraph(Stock Stck, Stock.Interval Period) { int length = 0; double startPost = 0; double endPOs = 0; List <TradingPeriod> TradingList = new List <TradingPeriod>(); switch (Period) { case Stock.Interval.Hour: length = Stck.HourlyHist.Count; TradingList = Stck.HourlyHist; startPost = length + 6; endPOs = length - 50; break; case Stock.Interval.Day: length = Stck.DailyHist.Count; TradingList = Stck.DailyHist; startPost = length + 6; endPOs = length - 110; break; case Stock.Interval.Week: length = Stck.WeeklyHist.Count; TradingList = Stck.WeeklyHist; startPost = length + 6; endPOs = length - 80; break; case Stock.Interval.Month: length = Stck.MonthlyHist.Count; TradingList = Stck.MonthlyHist; startPost = length + 3; endPOs = length - 48; break; } VolumeStyle style = VolumeStyle.Combined; bool naturalY = false; bool naturalV = false; var pm = new PlotModel { }; var series = new CandleStickAndVolumeSeries { PositiveColor = OxyColors.DarkGreen, NegativeColor = OxyColors.Red, PositiveHollow = false, NegativeHollow = false, SeparatorColor = OxyColors.Gray, SeparatorLineStyle = LineStyle.Dash, VolumeStyle = VolumeStyle.Combined }; // create bars foreach (var v in TradingList) { OhlcvItem Temp = new OhlcvItem(); Temp.BuyVolume = (v.Volume); Temp.Close = v.Close; Temp.High = v.High; Temp.Low = v.Low; Temp.Open = v.Open; Temp.X = v.Index; series.Append(Temp); } // create visible window var Istart = length - 10; var Iend = length - 1; var Ymin = series.Items.Skip((int)endPOs).Take((int)startPost - (int)endPOs + 1).Select(x => x.Low).Min(); var Ymax = series.Items.Skip((int)endPOs).Take((int)startPost - (int)endPOs + 1).Select(x => x.High).Max(); // setup axes var timeAxis = new OxyPlot.Axes.DateTimeAxis { Position = AxisPosition.Bottom, Minimum = endPOs, Maximum = startPost, //StartPosition = Xmax - TimeSpan.FromDays(180).Ticks, //EndPosition = Xmax, }; var barAxis = new OxyPlot.Axes.LogarithmicAxis() { Position = AxisPosition.Left, Key = series.BarAxisKey, StartPosition = 0.15, EndPosition = 1.0, Minimum = naturalY ? double.NaN : Ymin, Maximum = naturalY ? double.NaN : Ymax, }; var volAxis = new OxyPlot.Axes.LinearAxis() { Position = AxisPosition.Left, Key = series.VolumeAxisKey, StartPosition = 0.0, EndPosition = 0.15, Minimum = naturalV ? double.NaN : 0, Maximum = naturalV ? double.NaN : TradingList.Max(x => x.Volume) }; switch (style) { case VolumeStyle.None: barAxis.Key = null; barAxis.StartPosition = 0.0; pm.Axes.Add(timeAxis); pm.Axes.Add(barAxis); break; case VolumeStyle.Combined: case VolumeStyle.Stacked: pm.Axes.Add(timeAxis); pm.Axes.Add(barAxis); pm.Axes.Add(volAxis); break; case VolumeStyle.PositiveNegative: volAxis.Minimum = naturalV ? double.NaN : -5000; pm.Axes.Add(timeAxis); pm.Axes.Add(barAxis); pm.Axes.Add(volAxis); break; } pm.Series.Add(series); if (naturalY == false) { timeAxis.AxisChanged += (sender, e) => AdjustYExtent(series, timeAxis, barAxis); //timeAxis.AxisChanged += (sender, e) => AdjustYExtent(series, timeAxis, volAxis); } ///Adding Pivot Annotation /// Stck.GetPivots(Period); var ResistanceLines = new List <OxyPlot.Annotations.LineAnnotation>(); var FirstOrderPivots = new List <OxyPlot.Annotations.PointAnnotation>(); var SecondOrderPivots = new List <OxyPlot.Annotations.PointAnnotation>(); var ThirdOrderPivots = new List <OxyPlot.Annotations.PointAnnotation>(); foreach (var f in TradingList) { if (f.IsPivotHigh[0]) { FirstOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation() { Fill = OxyColors.LawnGreen, X = f.Index, Y = f.High }); } if (f.IsPivotHigh[1]) { SecondOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation() { Fill = OxyColors.Green, X = f.Index, Y = f.High }); } if (f.IsPivotHigh[2]) { ThirdOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation() { Fill = OxyColors.DarkGreen, X = f.Index, Y = f.High }); } if (f.IsPivotLow[0]) { FirstOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation() { Fill = OxyColors.Pink, X = f.Index, Y = f.Low }); } if (f.IsPivotLow[1]) { SecondOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation() { Fill = OxyColors.Red, X = f.Index, Y = f.Low }); } if (f.IsPivotLow[2]) { ThirdOrderPivots.Add(new OxyPlot.Annotations.PointAnnotation() { Fill = OxyColors.DarkRed, X = f.Index, Y = f.Low }); } } ResistanceLines = MarketStructure.DefineSupportResistanceZonesPivots(Stck, Period); GraphOverlays FOP = new GraphOverlays(); GraphOverlays SOP = new GraphOverlays(); GraphOverlays TOP = new GraphOverlays(); GraphOverlays Lines = new GraphOverlays(); FOP.Name = "First Order Pivot"; SOP.Name = "Second Order Pivot"; TOP.Name = "Third Order Pivot"; Lines.Name = "Resistance Lines"; FOP.Overlay = FirstOrderPivots; SOP.Overlay = SecondOrderPivots; TOP.Overlay = ThirdOrderPivots; Lines.Overlay = ResistanceLines; FOP.Period = Period; SOP.Period = Period; TOP.Period = Period; Lines.Period = Period; CurrentOverlays.Add(FOP); CurrentOverlays.Add(SOP); CurrentOverlays.Add(TOP); CurrentOverlays.Add(Lines); ///Adding line annotation... var la = new OxyPlot.Annotations.LineAnnotation { Type = LineAnnotationType.Horizontal, Y = TradingList.Last().Close }; la.MouseDown += (s, e) => { if (e.ChangedButton != OxyMouseButton.Left) { return; } la.StrokeThickness *= 5; pm.InvalidatePlot(false); e.Handled = true; }; // Handle mouse movements (note: this is only called when the mousedown event was handled) la.MouseMove += (s, e) => { la.Y = la.InverseTransform(e.Position).Y; la.Text = string.Format("{0:0.###}", la.Y); pm.InvalidatePlot(false); e.Handled = true; }; la.MouseUp += (s, e) => { la.StrokeThickness /= 5; pm.InvalidatePlot(false); e.Handled = true; }; pm.Annotations.Add(la); OxyPlot.Annotations.ArrowAnnotation tmp = null; pm.MouseDown += (s, e) => { if (e.ChangedButton == OxyMouseButton.Left) { // Create a new arrow annotation tmp = new OxyPlot.Annotations.ArrowAnnotation(); tmp.HeadLength = 0; tmp.StartPoint = tmp.EndPoint = timeAxis.InverseTransform(e.Position.X, e.Position.Y, barAxis); pm.Annotations.Add(tmp); e.Handled = true; } if (e.ChangedButton == OxyMouseButton.Middle) { //delete old arrow annotation if (e.HitTestResult != null) { if (e.HitTestResult.Element.GetType() == typeof(OxyPlot.Annotations.ArrowAnnotation)) { tmp = (OxyPlot.Annotations.ArrowAnnotation)e.HitTestResult.Element; pm.Annotations.Remove(tmp); e.Handled = true; } } } }; // Handle mouse movements (note: this is only called when the mousedown event was handled) pm.MouseMove += (s, e) => { if (tmp != null) { // Modify the end point tmp.EndPoint = timeAxis.InverseTransform(e.Position.X, e.Position.Y, barAxis); tmp.FontWeight = FontWeights.Bold; tmp.Text = string.Format("{0:0.##}%", ((tmp.StartPoint.Y - tmp.EndPoint.Y) * -100) / tmp.StartPoint.Y); // Redraw the plot pm.InvalidatePlot(false); e.Handled = true; } }; pm.MouseUp += (s, e) => { if (tmp != null) { tmp = null; e.Handled = true; } }; pm.Title = Stck.StockName; var controller = new PlotController(); //controller.UnbindAll(); //controller.BindMouseDown(OxyMouseButton.Middle, PlotCommands); //controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt); //controller.BindMouseDown(OxyMouseButton.Middle, ); return(new Example(pm, controller)); }
public void GetPivots(Stock.Interval Period) { List <TradingPeriod> TempList = new List <TradingPeriod>(); List <TradingPeriod> Hist = new List <TradingPeriod>(); switch (Period) { case Interval.Hour: Hist = HourlyHist; break; case Interval.Day: Hist = DailyHist; break; case Interval.Week: Hist = WeeklyHist; break; case Interval.Month: Hist = MonthlyHist; break; } for (int i = 1; i < Hist.Count - 1; i++) { if (Hist[i].High > Hist[i - 1].High && Hist[i].High > Hist[i + 1].High) { Hist[i].IsPivotHigh[0] = true; } if (Hist[i].Low < Hist[i - 1].Low && Hist[i].Low < Hist[i + 1].Low) { Hist[i].IsPivotLow[0] = true; } } TempList = Hist.Where(x => x.IsPivotHigh[0]).ToList(); for (int i = 1; i < TempList.Count - 1; i++) { if (TempList[i].High > TempList[i - 1].High && TempList[i].High > TempList[i + 1].High) { Hist[Hist.IndexOf(TempList[i])].IsPivotHigh[1] = true; //Hist[Hist.IndexOf(TempList[i])].IsPivotHigh[0] = false; } } TempList = Hist.Where(x => x.IsPivotHigh[1]).ToList(); for (int i = 1; i < TempList.Count - 1; i++) { if (TempList[i].High > TempList[i - 1].High && TempList[i].High > TempList[i + 1].High) { Hist[Hist.IndexOf(TempList[i])].IsPivotHigh[2] = true; //Hist[Hist.IndexOf(TempList[i])].IsPivotHigh[1] = false; } } TempList = Hist.Where(x => x.IsPivotLow[0]).ToList(); for (int i = 1; i < TempList.Count - 1; i++) { if (TempList[i].Low < TempList[i - 1].Low && TempList[i].Low < TempList[i + 1].Low) { Hist[Hist.IndexOf(TempList[i])].IsPivotLow[1] = true; //Hist[Hist.IndexOf(TempList[i])].IsPivotLow[0] = false; } } TempList = Hist.Where(x => x.IsPivotLow[1]).ToList(); for (int i = 1; i < TempList.Count - 1; i++) { if (TempList[i].Low < TempList[i - 1].Low && TempList[i].Low < TempList[i + 1].Low) { Hist[Hist.IndexOf(TempList[i])].IsPivotLow[2] = true; //Hist[Hist.IndexOf(TempList[i])].IsPivotLow[1] = false; } } }
public async void BuildStockHist(StreamReader YahooData, string Ticker, Stock.Interval Period) { switch (Period) { case Interval.Hour: StockName = Ticker; HourlyHist = new List <TradingPeriod>(); string a = ""; while (!a.Contains("volume:")) { a = YahooData.ReadLine(); //YahooData.ReadLine(); } YahooData.ReadLine(); if (!YahooData.EndOfStream) { DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); List <double> Opens = new List <double>(); List <double> Highs = new List <double>(); List <double> Lows = new List <double>(); List <double> Closes = new List <double>(); List <long> volumes = new List <long>(); int Currenthour = -1; while (!YahooData.EndOfStream) { string Temp = YahooData.ReadLine(); string[] TmpArry = Temp.Split(','); double open; double high; double low; double close; long volume; long time; long.TryParse(TmpArry[0], out time); double.TryParse(TmpArry[1], out close); double.TryParse(TmpArry[2], out high); double.TryParse(TmpArry[3], out low); double.TryParse(TmpArry[4], out open); long.TryParse(TmpArry[5], out volume); DateTime Temporig = origin; Temporig = Temporig.AddSeconds(time); if (Currenthour == -1) { Currenthour = Temporig.Hour; } if (Temporig.Hour == Currenthour) { Opens.Add(open); Highs.Add(high); Lows.Add(low); Closes.Add(close); volumes.Add(volume); } else { Currenthour = Temporig.Hour; TradingPeriod TmpDay = new TradingPeriod() { Day = Convert.ToDateTime(Temporig).ToLocalTime(), Open = Opens.First(), High = Highs.Max(), Low = Lows.Min(), Close = Closes.Last(), Volume = volumes.Sum(), }; Opens = new List <double>(); Highs = new List <double>(); Lows = new List <double>(); Closes = new List <double>(); volumes = new List <long>(); Opens.Add(open); Highs.Add(high); Lows.Add(low); Closes.Add(close); volumes.Add(volume); HourlyHist.Add(TmpDay); } } HourlyHist = HourlyHist.OrderBy(x => x.Day.Ticks).ToList(); for (int i = 1; i < HourlyHist.Count; i++) { HourlyHist[i].ReturnSeries = HourlyHist[i].Close / HourlyHist[i - 1].Close - 1; } for (int i = 0; i < HourlyHist.Count; i++) { HourlyHist[i].Index = i + 1; } } break; case Interval.Day: StockName = Ticker; DailyHist = new List <TradingPeriod>(); YahooData.ReadLine(); while (!YahooData.EndOfStream) { string Temp = YahooData.ReadLine(); string[] TmpArry = Temp.Split(','); double open; double high; double low; double close; double adjclose; long volume; double.TryParse(TmpArry[1], out open); double.TryParse(TmpArry[2], out high); double.TryParse(TmpArry[3], out low); double.TryParse(TmpArry[4], out close); long.TryParse(TmpArry[5], out volume); double.TryParse(TmpArry[6], out adjclose); TradingPeriod TmpDay = new TradingPeriod() { Day = Convert.ToDateTime(TmpArry[0]).ToLocalTime(), Open = open, High = high, Low = low, Close = close, Volume = volume, AdjClose = adjclose }; DailyHist.Add(TmpDay); } DailyHist = DailyHist.OrderBy(x => x.Day.Ticks).ToList(); for (int i = 1; i < DailyHist.Count; i++) { DailyHist[i].ReturnSeries = DailyHist[i].AdjClose / DailyHist[i - 1].AdjClose - 1; } for (int i = 0; i < DailyHist.Count; i++) { DailyHist[i].Index = i + 1; } break; case Interval.Week: StockName = Ticker; WeeklyHist = new List <TradingPeriod>(); YahooData.ReadLine(); while (!YahooData.EndOfStream) { string Temp = YahooData.ReadLine(); string[] TmpArry = Temp.Split(','); double open; double high; double low; double close; double adjclose; long volume; double.TryParse(TmpArry[1], out open); double.TryParse(TmpArry[2], out high); double.TryParse(TmpArry[3], out low); double.TryParse(TmpArry[4], out close); long.TryParse(TmpArry[5], out volume); double.TryParse(TmpArry[6], out adjclose); TradingPeriod TmpWeek = new TradingPeriod() { Day = Convert.ToDateTime(TmpArry[0]).ToLocalTime(), Open = open, High = high, Low = low, Close = close, Volume = volume, AdjClose = adjclose }; WeeklyHist.Add(TmpWeek); } WeeklyHist = WeeklyHist.OrderBy(x => x.Day.Ticks).ToList(); for (int i = 1; i < WeeklyHist.Count; i++) { WeeklyHist[i].ReturnSeries = WeeklyHist[i].AdjClose / WeeklyHist[i - 1].AdjClose - 1; } for (int i = 0; i < WeeklyHist.Count; i++) { WeeklyHist[i].Index = i + 1; } break; case Interval.Month: StockName = Ticker; MonthlyHist = new List <TradingPeriod>(); YahooData.ReadLine(); while (!YahooData.EndOfStream) { string Temp = YahooData.ReadLine(); string[] TmpArry = Temp.Split(','); double open; double high; double low; double close; double adjclose; long volume; double.TryParse(TmpArry[1], out open); double.TryParse(TmpArry[2], out high); double.TryParse(TmpArry[3], out low); double.TryParse(TmpArry[4], out close); long.TryParse(TmpArry[5], out volume); double.TryParse(TmpArry[6], out adjclose); TradingPeriod TmpWeek = new TradingPeriod() { Day = Convert.ToDateTime(TmpArry[0]).ToLocalTime(), Open = open, High = high, Low = low, Close = close, Volume = volume, AdjClose = adjclose }; MonthlyHist.Add(TmpWeek); } MonthlyHist = MonthlyHist.OrderBy(x => x.Day.Ticks).ToList(); for (int i = 1; i < MonthlyHist.Count; i++) { MonthlyHist[i].ReturnSeries = MonthlyHist[i].AdjClose / MonthlyHist[i - 1].AdjClose - 1; } for (int i = 0; i < MonthlyHist.Count; i++) { MonthlyHist[i].Index = i + 1; } break; } }
public static List <OxyPlot.Annotations.LineAnnotation> DefineSupportResistanceZonesPivots(Stock T, Stock.Interval Period) { List <OxyPlot.Annotations.LineAnnotation> SAR = new List <OxyPlot.Annotations.LineAnnotation>(); List <TradingPeriod> TList = new List <TradingPeriod>(); int VolaTilityRange = 0; int min = 0; double AnnualisationFactor = 0; switch (Period) { case Stock.Interval.Hour: TList = T.HourlyHist; VolaTilityRange = 120; AnnualisationFactor = 252 * 6; min = 10; break; case Stock.Interval.Day: TList = T.DailyHist; VolaTilityRange = 21; AnnualisationFactor = 252; min = 10; break; case Stock.Interval.Week: TList = T.WeeklyHist; VolaTilityRange = 4; AnnualisationFactor = 52; min = 3; break; case Stock.Interval.Month: TList = T.MonthlyHist; VolaTilityRange = 1; AnnualisationFactor = 12; min = 3; break; } /// Get Support /// Adam Grimes formula List <TradingPeriod> LowPivots = new List <TradingPeriod>(TList.Where(x => x.IsPivotLow[0])); for (int i = LowPivots.Count - 1; i >= 0; i--) { if (i < VolaTilityRange) { VolaTilityRange = i; } List <double> LogReturns = new List <double>(); List <double> Prices = TList.GetRange(TList.IndexOf(LowPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.AdjClose).ToList(); for (int MN = 1; MN < VolaTilityRange; MN++) { double Temp = Math.Log(Prices[MN] / Prices[MN - 1]); LogReturns.Add(Temp); } double STDev = Accord.Statistics.Measures.StandardDeviation(LogReturns.ToArray()) * Math.Sqrt(AnnualisationFactor); //double STDev = Accord.Statistics.Measures.StandardDeviation(TList.GetRange(TList.IndexOf(LowPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.ReturnSeries).ToArray()) * Math.Sqrt(AnnualisationFactor); //double yOne = LowPivots[i].AdjClose + STDev; //double yTwo = LowPivots[i].AdjClose - STDev; double yOne = Math.Abs(LowPivots[i].Close * (1 + Math.Pow(STDev, 2))); double yTwo = Math.Abs(LowPivots[i].Close * (1 - Math.Pow(STDev, 2))); List <TradingPeriod> Temps = new List <TradingPeriod>(); for (int x = i; x >= 0; x--) { if (LowPivots[x].Close > yTwo && LowPivots[x].Close < yOne) { Temps.Add(LowPivots[x]); } else { break; } } for (int x = i; x < LowPivots.Count - 1; x++) { if (LowPivots[x].Close > yTwo && LowPivots[x].Close < yOne) { Temps.Add(LowPivots[x]); } else { break; } } if (Temps.Count > min) { OxyPlot.Annotations.LineAnnotation temp = new OxyPlot.Annotations.LineAnnotation(); OxyPlot.Annotations.LineAnnotation temp2 = new OxyPlot.Annotations.LineAnnotation(); temp.Type = LineAnnotationType.Horizontal; temp.MinimumX = Temps.Min(x => x.Index); temp.MaximumX = Temps.Max(x => x.Index); //if (Period != Stock.Interval.Week) temp.Y = Temps.OrderBy(x => x.Close).Take(2).Last().Close; //else temp.Y = Temps.Min(x => x.Close); temp.Y = Temps.Min(x => x.Close); temp.Color = OxyColors.Red; temp2.Type = LineAnnotationType.Horizontal; temp2.MinimumX = Temps.Min(x => x.Index); temp2.MaximumX = Temps.Max(x => x.Index); //if (Period != Stock.Interval.Week) temp2.Y = Temps.OrderByDescending(x => x.Close).Take(2).Last().Close; //else temp2.Y = Temps.Max(x => x.Close); temp2.Y = Temps.Max(x => x.Close); temp2.Color = OxyColors.Red; //double High1 = Math.Abs(temp.Y * (1 + Math.Pow(STDev, 2))); //double Low1 = Math.Abs(temp.Y * (1 - Math.Pow(STDev, 2))); //double High2 = Math.Abs(temp2.Y * (1 + Math.Pow(STDev, 2))); //double Low2 = Math.Abs(temp2.Y * (1 - Math.Pow(STDev, 2))); //List<OxyPlot.Annotations.LineAnnotation> MoreTemps1 = new List<LineAnnotation>(); //List<OxyPlot.Annotations.LineAnnotation> MoreTemps2 = new List<LineAnnotation>(); //MoreTemps1 = SAR.Where(x => x.Y < High1 && x.Y > Low1).ToList(); //MoreTemps2 = SAR.Where(x => x.Y < High2 && x.Y > Low2).ToList(); //if (MoreTemps1.Count > 0) //{ // temp.MinimumX = MoreTemps1.Min(x => x.MinimumX); // temp.MaximumX = MoreTemps1.Max(x => x.MaximumX); // temp.Y = MoreTemps1.Average(x => x.Y); // //foreach (var v in MoreTemps1) // //{ // // SAR.Remove(v); // //} // SAR.Add(temp); //} //else SAR.Add(temp); //if (MoreTemps2.Count > 0) //{ // temp2.MinimumX = MoreTemps2.Min(x => x.MinimumX); // temp2.MaximumX = MoreTemps2.Max(x => x.MaximumX); // temp2.Y = MoreTemps2.Average(x => x.Y); // //foreach (var c in MoreTemps2) // //{ // // SAR.Remove(c); // //} // SAR.Add(temp2); //} //else SAR.Add(temp2); SAR.Add(temp); SAR.Add(temp2); } foreach (var t in Temps) { i--; TList.Remove(TList.Last()); } } /// Get Resistance /// switch (Period) { case Stock.Interval.Hour: TList = T.HourlyHist; VolaTilityRange = 120; AnnualisationFactor = 252 * 6; min = 10; break; case Stock.Interval.Day: TList = T.DailyHist; VolaTilityRange = 21; AnnualisationFactor = 252; min = 10; break; case Stock.Interval.Week: TList = T.WeeklyHist; VolaTilityRange = 4; AnnualisationFactor = 52; min = 2; break; case Stock.Interval.Month: TList = T.MonthlyHist; VolaTilityRange = 1; AnnualisationFactor = 12; min = 1; break; } List <TradingPeriod> HighPivots = new List <TradingPeriod>(TList.Where(x => x.IsPivotHigh[0])); for (int i = HighPivots.Count - 1; i >= 0; i--) { if (i < VolaTilityRange) { VolaTilityRange = i; } List <double> LogReturns = new List <double>(); List <double> Prices = TList.GetRange(TList.IndexOf(HighPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.AdjClose).ToList(); for (int MN = 1; MN < VolaTilityRange; MN++) { double Temp = Math.Log(Prices[MN] / Prices[MN - 1]); LogReturns.Add(Temp); } double STDev = Accord.Statistics.Measures.StandardDeviation(LogReturns.ToArray()) * Math.Sqrt(AnnualisationFactor); //double STDev = Accord.Statistics.Measures.StandardDeviation(TList.GetRange(TList.IndexOf( HighPivots[i]) - VolaTilityRange, VolaTilityRange).Select(x => x.ReturnSeries).ToArray()) * Math.Sqrt(AnnualisationFactor); double yOne = Math.Abs(HighPivots[i].Close * (1 + Math.Pow(STDev, 2))); double yTwo = Math.Abs(HighPivots[i].Close * (1 - Math.Pow(STDev, 2))); //double yOne = HighPivots[i].AdjClose + STDev; //double yTwo = HighPivots[i].AdjClose - STDev; List <TradingPeriod> Temps = new List <TradingPeriod>(); for (int x = i; x >= 0; x--) { if (HighPivots[x].High > yTwo && HighPivots[x].High < yOne) { Temps.Add(HighPivots[x]); } else { break; } } for (int x = i; x < HighPivots.Count - 1; x++) { if (HighPivots[x].High > yTwo && HighPivots[x].High < yOne) { Temps.Add(HighPivots[x]); } else { break; } } if (Temps.Count > min) { OxyPlot.Annotations.LineAnnotation temp = new OxyPlot.Annotations.LineAnnotation(); OxyPlot.Annotations.LineAnnotation temp2 = new OxyPlot.Annotations.LineAnnotation(); temp.Type = LineAnnotationType.Horizontal; temp.MinimumX = Temps.Min(x => x.Index); temp.MaximumX = Temps.Max(x => x.Index); //if (Period != Stock.Interval.Week) temp2.Y = Temps.OrderByDescending(x => x.Close).Take(2).Last().Close; //else temp2.Y = Temps.Max(x => x.Close); temp2.Y = Temps.Max(x => x.Close); temp.Color = OxyColors.LawnGreen; temp2.Type = LineAnnotationType.Horizontal; temp2.MinimumX = Temps.Min(x => x.Index); temp2.MaximumX = Temps.Max(x => x.Index); //if (Period != Stock.Interval.Week) temp.Y = Temps.OrderBy(x => x.Close).Take(2).Last().Close; //else temp.Y = Temps.Min(x => x.Close); temp.Y = Temps.Min(x => x.Close); temp2.Color = OxyColors.LawnGreen; SAR.Add(temp); SAR.Add(temp2); } foreach (var t in Temps) { i--; TList.Remove(HighPivots.Last()); } } return(SAR); }