public int?GetBarIndexAtPosition(int position) { var barIndex = position / Song.SamplesPerBar; if (barIndex >= Bars.Count()) { return(null); } return(barIndex); }
protected override void OnCalculate() { TimeFrame tf = (TimeFrame)Bars.TimeFrame; if (Bars != null && Bars.Count() > 0 && Times != null && Times.Count > 0 && this.IsProcessingBarIndexLast && (tf.Periodicity != DatafeedHistoryPeriodicity.Year && tf.Periodicity != DatafeedHistoryPeriodicity.Day && tf.Periodicity != DatafeedHistoryPeriodicity.Week)) { for (int i = 0; i < this.HowManyDays; i++) { if (_showopen) { AddChartLine("Open_" + i.ToString(), this.IsAutoAdjustableScale, Times[1][i], Opens[1][i], Times[0][0], Opens[1][i], this.Color_O, this.DashStyle_O, this.LineWidth_O); } if (_showhigh) { AddChartLine("High_" + i.ToString(), this.IsAutoAdjustableScale, Times[1][i], Highs[1][i], Times[0][0], Highs[1][i], this.Color_H, this.DashStyle_H, this.LineWidth_H); } if (_showlow) { AddChartLine("Low_" + i.ToString(), this.IsAutoAdjustableScale, Times[1][i], Lows[1][i], Times[0][0], Lows[1][i], this.Color_L, this.DashStyle_L, this.LineWidth_L); } if (_showclose) { AddChartLine("Close_" + i.ToString(), this.IsAutoAdjustableScale, Times[1][i], Closes[1][i], Times[0][0], Closes[1][i], this.Color_C, this.DashStyle_C, this.LineWidth_C); } if (_showlines) { DateTime enddrawing_string = Times[0][0].AddSeconds(this.TimeFrame.GetSeconds() + this.TimeFrame.GetSeconds() * 0.15); if (_showopen) { AddChartText("String_Open_" + i.ToString(), this.IsAutoAdjustableScale, "O " + (i + 1).ToString(), enddrawing_string, Opens[1][i], 0, this.Color_O, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } if (_showhigh) { AddChartText("String_High_" + i.ToString(), this.IsAutoAdjustableScale, "H " + (i + 1).ToString(), enddrawing_string, Highs[1][i], 0, this.Color_H, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } if (_showlow) { AddChartText("String_Low_" + i.ToString(), this.IsAutoAdjustableScale, "L " + (i + 1).ToString(), enddrawing_string, Lows[1][i], 0, this.Color_L, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } if (_showclose) { AddChartText("String_Close_" + i.ToString(), this.IsAutoAdjustableScale, "C " + (i + 1).ToString(), enddrawing_string, Closes[1][i], 0, this.Color_C, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } } } } }
public int GetLastNonEmptyBarIndex() { int lastBarIndex = 0; for (int barIndex = 0; barIndex < Bars.Count(); barIndex++) { var bar = Bars[barIndex]; if (bar.Buffer != null && barIndex > lastBarIndex) { lastBarIndex = barIndex; } } return(lastBarIndex); }
/// <summary> /// Calculate and draw the high & low lines. /// </summary> private void calculateanddrawhighlowlines() { switch (FindHighLowTimeFrame_Type) { case FindHighLowTimeFrame_Type.Session: //Draw it for the session DateTime thesessiondatetime = Time[0]; if (this.Sessionsago != 0) { //todo subtract the date IEnumerable <DateTime> datelist = Bars.Select(x => x.Time.Date).Distinct(); if (datelist.Count() - 1 < this.Sessionsago) { //do nothing return; } else { thesessiondatetime = datelist.GetByIndex(datelist.Count() - 1 - this.Sessionsago); } } //Default timeframe is this Session DateTime start = new DateTime(thesessiondatetime.Year, thesessiondatetime.Month, thesessiondatetime.Day, 0, 0, 0); DateTime end = new DateTime(thesessiondatetime.Year, thesessiondatetime.Month, thesessiondatetime.Day, 23, 59, 59); //Override if we want this if (this.UseDedicatedTimeSpan) { start = new DateTime(thesessiondatetime.Year, thesessiondatetime.Month, thesessiondatetime.Day, this.Time_Start.Hours, this.Time_Start.Minutes, this.Time_Start.Seconds); end = new DateTime(thesessiondatetime.Year, thesessiondatetime.Month, thesessiondatetime.Day, this.Time_End.Hours, this.Time_End.Minutes, this.Time_End.Seconds); } //Select all data and find high & low. IEnumerable <IBar> list = Bars.Where(x => x.Time >= start).Where(x => x.Time <= end); //We save the high and low values in public variables to get access from other scripts this.LastLow = list.Where(x => x.Low == list.Min(y => y.Low)).LastOrDefault().Low; this.LastHigh = list.Where(x => x.High == list.Max(y => y.High)).LastOrDefault().High; this.LastMiddle = this.LastLow + ((this.LastHigh - this.LastLow) / 2); //Draw current lines for this day session if (Time[0].Date == DateTime.Now.Date) { if (this.IsDrawLowLineEnabled) { AddChartHorizontalLine("LowLine" + start.Ticks, this.IsAutoAdjustableScale, this.LastLow, this.CurrentSessionLineColor, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } if (this.IsDrawHighLineEnabled) { AddChartHorizontalLine("HighLine" + start.Ticks, this.IsAutoAdjustableScale, this.LastHigh, this.CurrentSessionLineColor, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } if (this.IsDrawMiddleLineEnabled) { AddChartHorizontalLine("MiddleLine" + start.Ticks, this.IsAutoAdjustableScale, this.LastMiddle, this.CurrentSessionLineColor, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } } //Draw a rectangle at the dedicated time frame if (this.IsDrawAreaplotEnabled) { AddChartRectangle("HighLowRect" + start.Ticks, this.IsAutoAdjustableScale, start, this.LastLow, end, this.LastHigh, this.Color_TimeSpan, this.Color_TimeSpan, this.Opacity); } break; case FindHighLowTimeFrame_Type.Candle: //Draw it for the candles if (Bars.Count() - 1 >= this.CandlesAgo) { DateTime startcandle = Bars[this.CandlesAgo].Time.Date; double lastmiddle = Bars[this.CandlesAgo].Low + (Bars[this.CandlesAgo].Range / 2); if (this.IsDrawMiddleLineEnabled) { AddChartHorizontalLine("MiddleLineOnCandle" + startcandle.Ticks, this.IsAutoAdjustableScale, lastmiddle, this.CurrentSessionLineColor, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } } break; case FindHighLowTimeFrame_Type.BarsAvailable: //Draw it for the candles if (Bars.Count() >= 1) { //We save the high and low values in public variables to get access from other scripts this.LastLow = Bars.Where(x => x.Low == Bars.Min(y => y.Low)).LastOrDefault().Low; this.LastHigh = Bars.Where(x => x.High == Bars.Max(y => y.High)).LastOrDefault().High; this.LastMiddle = this.LastLow + ((this.LastHigh - this.LastLow) / 2); string datenow = DateTime.Now.ToString(); if (this.IsDrawLowLineEnabled) { AddChartHorizontalLine("LowLine" + datenow, this.IsAutoAdjustableScale, this.LastLow, this.CurrentSessionLineColor, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } if (this.IsDrawHighLineEnabled) { AddChartHorizontalLine("HighLine" + datenow, this.IsAutoAdjustableScale, this.LastHigh, this.CurrentSessionLineColor, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } if (this.IsDrawMiddleLineEnabled) { AddChartHorizontalLine("MiddleLine" + datenow, this.IsAutoAdjustableScale, this.LastMiddle, this.CurrentSessionLineColor, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } } break; default: throw new NotImplementedException("FindHighLowTimeFrame: enum FindHighLowTimeFrame_Type is not defined", null); } }
protected override void OnCalculate() { TimeFrame tf = (TimeFrame)Bars.TimeFrame; if (Bars != null && Bars.Count() > 0 && Times != null && Times.Count > 0 && this.IsProcessingBarIndexLast && (tf.Periodicity != DatafeedHistoryPeriodicity.Year && tf.Periodicity != DatafeedHistoryPeriodicity.Day && tf.Periodicity != DatafeedHistoryPeriodicity.Week)) { IBar datetillendbar = Bars.Where(x => x.Time.Date == Times[0][0].Date).Last(); if (datetillendbar != null) { DateTime datetillend = datetillendbar.Time; DateTime date = Times[1][0]; //if (!_extendlines) //{ // IEnumerable<IBar> lisdateend = Bars.Where(x => x.Time.Date == date.Date); // datetillend = date.Date.AddDays(1).AddSeconds(-1); // if (lisdateend != null && lisdateend.Count() > 0) // { // datetillend = Bars.Where(x => x.Time.Date == date.Date).Last().Time; // } //} IEnumerable <IBar> list = Bars.Where(x => x.Time.Date == date.Date); DateTime startdate = date.Date; if (list != null && list.Count() > 0) { startdate = list.First().Time; } if (_showopen) { AddChartLine("Open_" + date.ToString(), this.IsAutoAdjustableScale, startdate, Opens[1][0], datetillend, Opens[1][0], this.Color_O, this.DashStyle_O, this.LineWidth_O); } if (_showhigh) { AddChartLine("High_" + date.ToString(), this.IsAutoAdjustableScale, startdate, Highs[1][0], datetillend, Highs[1][0], this.Color_H, this.DashStyle_H, this.LineWidth_H); } if (_showlow) { AddChartLine("Low_" + date.ToString(), this.IsAutoAdjustableScale, startdate, Lows[1][0], datetillend, Lows[1][0], this.Color_L, this.DashStyle_L, this.LineWidth_L); } if (_showclose) { AddChartLine("Close_" + date.ToString(), this.IsAutoAdjustableScale, startdate, Closes[1][0], datetillend, Closes[1][0], this.Color_C, this.DashStyle_C, this.LineWidth_C); } if (_showlines) { DateTime enddrawing_string = datetillend.AddSeconds(this.TimeFrame.GetSeconds() + this.TimeFrame.GetSeconds() * 0.15); if (_showopen) { AddChartText("String_Open_" + date.ToString(), this.IsAutoAdjustableScale, "CDO", enddrawing_string, Opens[1][0], 0, this.Color_O, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } if (_showhigh) { AddChartText("String_High_" + date.ToString(), this.IsAutoAdjustableScale, "CDH", enddrawing_string, Highs[1][0], 0, this.Color_H, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } if (_showlow) { AddChartText("String_Low_" + date.ToString(), this.IsAutoAdjustableScale, "CDL", enddrawing_string, Lows[1][0], 0, this.Color_L, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } if (_showclose) { AddChartText("String_Close_" + date.ToString(), this.IsAutoAdjustableScale, "CDC", enddrawing_string, Closes[1][0], 0, this.Color_C, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); } } } } ////Output Listen //if (_showindicatorlines) //{ // this.Indicator_Curve_Open.Set(Opens[1][0]); // this.Indicator_Curve_High.Set(Highs[1][0]); // this.Indicator_Curve_Low.Set(Lows[1][0]); // this.Indicator_Curve_Close.Set(Closes[1][0]); //} }
protected override void OnCalculate() { if (_year == 0) { _year = Time[0].Year; } //DateTime lastDayOfYear = new DateTime(Time[0].Year + 1, 1, 1).AddDays(-1); if (_year < Time[0].Year) { AddChartVerticalLine("vline" + Time[0].Date.ToString(), 0, this.Color_Vertical_Line_FiscalEnd, this.Vertical_DashStyle, this.Vertical_Line_Width); //AddChartText("txt" + Time[0].Date.ToString(), Time[0].Year.ToString(), ProcessingBarIndexes[0] - Bars.Count() + 1, Low[0], this.Color_Horizontal_Line_FiscalEnd); AddChartText("txt" + Time[0].Date.ToString(), Time[0].Year.ToString(), ProcessingBarIndexes[0] - Chart.LastBarVisible + 1, Close[0], this.Color_Horizontal_Line_FiscalEnd); AddChartLine("hline" + Time[0].ToString(), 0, Close[0], ProcessingBarIndexes[0] - Bars.Count() + 1, Close[0], this.Color_Horizontal_Line_FiscalEnd); _year = Time[0].Year; } }