public override void OnUpdate(TickStatus args) { if (args != TickStatus.IsQuote) { C.GetValue(HistoryDataSeries.GetValue(PriceType.Close)); H.GetValue(HistoryDataSeries.GetValue(PriceType.High)); L.GetValue(HistoryDataSeries.GetValue(PriceType.Low));; var WH = ValueWhen(1, NW, Ref(HighestSince(1, NW, H), -1)); var WL = ValueWhen(1, NW, Ref(LowestSince(1, NW, L), -1)); var WCL = ValueWhen(1, NW, Ref(C, -1)); var BP = (WH + WL + WCL) / 3; var D = ((WH - WL) / 2) + BP; var B = BP - ((WH - WL) / 2); var D1 = (WH - WL) + BP; var B1 = BP - (WH - WL); var SB1 = BP - ((WH - WL) * 1.0618); var SB2 = BP - ((WH - WL) * 0.98382); var RB1 = ((WH - WL) * 1.0618) + BP; var RB2 = ((WH - WL) * 0.98382) + BP; Lines["RB2"].SetValue(RB2); Lines["RB1"].SetValue(RB1); Lines["D1"].SetValue(D1); Lines["D"].SetValue(D); Lines["BP"].SetValue(BP); Lines["B"].SetValue(B); Lines["B1"].SetValue(B1); Lines["SB1"].SetValue(SB1); Lines["SB2"].SetValue(SB2); } }
private void Entry() { if (HistoryDataSeries.Count - 1 <= period) { return; } double maValue1 = ma.GetValue(offset: 0, lineNumber: 0); double maValue2 = ma.GetValue(offset: 1, lineNumber: 0); double maValue3 = ma.GetValue(offset: 2, lineNumber: 0); double closePrice1 = HistoryDataSeries.GetValue(PriceType.Close, 0); double closePrice2 = HistoryDataSeries.GetValue(PriceType.Close, 1); double closePrice3 = HistoryDataSeries.GetValue(PriceType.Close, 2); var buySignal = maValue1 < closePrice1 && maValue2 < closePrice2 && maValue3 < closePrice3; tradeResult = new TradeResult(); if (buySignal) { tradeResult = OperationHandler(PositionSide.Long); } if (tradeResult != null && tradeResult.HasError) { Notification.Print("An error occured during order opening: " + tradeResult.Message); } }
private void CalcBar(int i) { var currentBarTime = HistoryDataSeries.GetTimeUtc(i); var indexDaily = dailyBars.FindInterval(currentBarTime); var indexWeekly = weeklyBars.FindInterval(currentBarTime); var indexMonthly = monthlyBars.FindInterval(currentBarTime); if (indexDaily >= 0) { var multiMaValue = dailyBars.GetClose(indexDaily); Lines[0].SetValue(multiMaValue, i); } if (indexWeekly >= 0) { var multiMaValue = weeklyBars.GetClose(indexWeekly); Lines[1].SetValue(multiMaValue, i); } if (indexMonthly >= 0) { var multiMaValue = monthlyBars.GetClose(indexMonthly); Lines[2].SetValue(multiMaValue, i); } string notAvailable = "is not available"; string dClose = !double.IsNaN(dailyClose)? dailyClose.ToString() : notAvailable; string wClose = !double.IsNaN(weeklyClose)? weeklyClose.ToString() : notAvailable; string mClose = !double.IsNaN(monthlyClose)? monthlyClose.ToString() : notAvailable; Notification.Comment($"\n\n \n\n\n Daily Close {dClose}\n\n Weekly Close {wClose}\n\n Monthy Close {mClose}"); }
private List <BoxContainer> fillBoxes(int rightOffset, int leftOffset, List <Exchange> properExchanges, int winNumber) { var listToDraw = new List <BoxContainer>(); for (int i = rightOffset; i <= leftOffset - 1; i++) { var date = HistoryDataSeries.GetTimeUtc(i); var exchanges = properExchanges.FindAll(exchange => exchange.IsEnable && isLeftBorder(exchange, i, date) || exchange.IsEnable && isRightBorder(exchange, i, date) || exchange.IsEnable && isFirstOnBorder(exchange, date) || exchange.IsEnable && isBetweenBorder(exchange, date, rightOffset, leftOffset)); exchanges.ForEach(exchange => { var newBox = new BoxContainer(); var beginDateTime = exchange.ExchangeDateTimeUTC(date, exchange.BeginTime); var endDateTime = exchange.ExchangeDateTimeUTC(date, exchange.EndTime); newBox.Name = exchange.Name; var beginDateTimeIndex = HistoryDataSeries.FindInterval(beginDateTime) == -1 ? getClossesIndex(beginDateTime) : HistoryDataSeries.FindInterval(beginDateTime); var endDateTimeIndex = HistoryDataSeries.FindInterval(endDateTime) == -1 ? getClossesIndex(endDateTime) : HistoryDataSeries.FindInterval(endDateTime); var min = HistoryDataSeries.GetTimeUtc(beginDateTimeIndex) < HistoryDataSeries.GetTimeUtc(endDateTimeIndex) ? HistoryDataSeries.GetTimeUtc(beginDateTimeIndex) : HistoryDataSeries.GetTimeUtc(endDateTimeIndex); var max = HistoryDataSeries.GetTimeUtc(beginDateTimeIndex) > HistoryDataSeries.GetTimeUtc(endDateTimeIndex) ? HistoryDataSeries.GetTimeUtc(beginDateTimeIndex) : HistoryDataSeries.GetTimeUtc(endDateTimeIndex); var highest = HistoryDataSeries.GetValue(PriceType.High, HistoryDataSeries.GetHighest(PriceType.High, new Interval(min, max))[0]); var lowest = HistoryDataSeries.GetValue(PriceType.Low, HistoryDataSeries.GetLowest(PriceType.Low, new Interval(min, max))[0]); newBox.LeftPoint = ChartSource.GetChartPoint(new TimeValue(beginDateTime, highest), winNumber); newBox.RightPoint = ChartSource.GetChartPoint(new TimeValue(endDateTime, lowest), winNumber); newBox.Color = beginDateTime <HistoryDataSeries.GetTimeUtc(0) && endDateTime > HistoryDataSeries.GetTimeUtc(0) ? Color.FromArgb(100, Color.CornflowerBlue) : Color.Transparent; listToDraw.Add(newBox); }); } var result = listToDraw.Distinct(new Comparer()).ToList(); return(result); }
// William %R private void WilliamR() { var upper = High(HistoryDataSeries.GetHighest(PriceType.High, new Interval(HistoryDataSeries.GetTimeUtc(length), DateTime.UtcNow)).FirstOrDefault()); var lower = Low(HistoryDataSeries.GetLowest(PriceType.Low, new Interval(HistoryDataSeries.GetTimeUtc(length), DateTime.UtcNow)).FirstOrDefault()); RPercentage[0] = 100 * (Close() - upper) / (upper - lower); }
private void DrawBarStamp(Color color, PrimitiveFigure primitiveFigure, bool up = false, double offset = 1) { var tickSize = HistoryDataSeries.HistoricalRequest.Instrument.MinimalTickSize; offset = offset * tickSize; BarStamps.Set(new BarStampPrimitiveFigure(color, 0, up ? HistoryDataSeries.GetValue(PriceType.High) + offsetPrimitive + offset : HistoryDataSeries.GetValue(PriceType.Low) - offsetPrimitive - offset, primitiveFigure)); }
private int isInside() { var bodyStatus = (HistoryDataSeries.GetValue(PriceType.Close) >= HistoryDataSeries.GetValue(PriceType.Open)) ? 1 : -1; var isInsidePattern = HistoryDataSeries.GetValue(PriceType.High) < HistoryDataSeries.GetValue(PriceType.High, 1) && HistoryDataSeries.GetValue(PriceType.Low) > HistoryDataSeries.GetValue(PriceType.Low, 1); return(isInsidePattern ? bodyStatus : 0); }
public override void OnPaintChart(object sender, PaintChartEventArgs args) { if (HistoryDataSeries.Count == 0) { return; } //draw circle on min max int winNumber = ChartSource.FindWindow(this); var winRect = ChartSource.GetAllWindows()[winNumber].WindowRectangle; args.Graphics.SetClip(winRect); var leftPoint = winRect.Location; var rightPoint = new Point(leftPoint.X + winRect.Width, leftPoint.Y); var leftTime = ChartSource.GetTimeValue(leftPoint, winNumber).TimeUtc; var rightTime = ChartSource.GetTimeValue(rightPoint, winNumber).TimeUtc; int leftOffset = HistoryDataSeries.FindInterval(leftTime); int rightOffset = HistoryDataSeries.FindInterval(rightTime); if (leftOffset == -1) { leftOffset = HistoryDataSeries.Count - 1; } if (rightOffset == -1) { rightOffset = 0; } var barWidth = ChartSource.BarsWidth; for (int i = rightOffset; i <= leftOffset; i++) { double val = Lines["MinMax"].GetValue(i); if (val == 0) { continue; } var dt = HistoryDataSeries.GetTimeUtc(i); var price = val == 1 ? HistoryDataSeries.GetValue(PriceType.High, i) : HistoryDataSeries.GetValue(PriceType.Low, i); var curPoint = ChartSource.GetChartPoint(new TimeValue(dt, price), winNumber); var brush = val == 1 ? maxBrush : minBrush; args.Graphics.FillEllipse(brush, curPoint.X, curPoint.Y - barWidth / 2, barWidth, barWidth); } }
public double ROC(double pastValue, int offset, ROC_RESULT type) { var result = Double.NaN; var lastClose = HistoryDataSeries.GetValue(PriceType.Close, offset); result = type == ROC_RESULT.Absolute ? lastClose - pastValue : (lastClose - pastValue) / pastValue * 100; return(result); }
private void ChartControl_MouseMove(object sender, MouseEventArgs e) { var point = ChartSource.PointToChart(Cursor.Position); //getting the cursor position in the client coordinates int curWinNumber = ChartSource.FindWindow(this); var timeValue = ChartSource.GetTimeValue(point, curWinNumber); var curTime = Tools.TimeConvertor.UtcToCurrentTimeZone(timeValue.TimeUtc); var offset = HistoryDataSeries.FindInterval(timeValue.TimeUtc); var strOffset = offset != -1 ? offset.ToString() : "Not Selected"; Notification.Comment($"Time: {curTime}, Price: {timeValue.Value}, BarIndex: {strOffset}"); }
/// <summary> /// Entry point. This function is called when new quote comes or new bar created /// </summary> public override void Update(TickStatus args) { var val = customIndicator.GetValue(); if (val == -1) { Notification.Print("New minimum reached: " + HistoryDataSeries.GetValue(PriceType.Low)); } else if (val == 1) { Notification.Print("New maximum reached: " + +HistoryDataSeries.GetValue(PriceType.High)); } }
public override void Update(TickStatus args) { if (HistoryDataSeries.Count == 1) { var timeRequest = HistoryDataSeries.HistoricalRequest as TimeHistoricalRequest; if (timeRequest == null) { return; } var interval = new Interval(HistoryDataSeries.GetTimeUtc(HistoryDataSeries.Count - 1), DateTime.UtcNow); hd1 = HistoryDataSeries; hd2 = HistoricalDataManager.Get(timeRequest.GetRequest(instrument2), interval); } }
public int getClossesIndex(DateTime time) { var resultDesc = -1; var _time = RoundMinutes(time); var resultAsc = -1; var _totalMinutesInBar = totalMinutesInBar; while (resultDesc == -1 && resultAsc == -1) { resultDesc = HistoryDataSeries.FindInterval(_time.AddMinutes(-_totalMinutesInBar)); resultAsc = HistoryDataSeries.FindInterval(_time.AddMinutes(+_totalMinutesInBar)); _totalMinutesInBar += totalMinutesInBar; } ; return(resultDesc == -1 ? resultAsc : resultDesc); }
/// <summary> /// Entry point. This function is called when new quote comes or new bar created /// </summary> public override void Update(TickStatus args) { double high = HistoryDataSeries.GetValue(PriceType.High); double low = HistoryDataSeries.GetValue(PriceType.Low); int val = 0; if (double.IsNaN(maxValue) || high >= maxValue) { maxValue = high; val = 1; } if (double.IsNaN(minValue) || low <= minValue) { minValue = low; val = -1; } Lines["MinMax"].SetValue(val); //Clear previuse min/max if (val != 0 && HistoryDataSeries.Count > 1) { for (int i = 1; i < HistoryDataSeries.Count; i++) { double prevValue = Lines["MinMax"].GetValue(i); double prevHigh = HistoryDataSeries.GetValue(PriceType.High, i); double prevLow = HistoryDataSeries.GetValue(PriceType.Low, i); if (prevValue == -1 && prevLow > minValue) { Lines["MinMax"].SetValue(0, i); } if (prevValue == 1 && prevHigh < maxValue) { Lines["MinMax"].SetValue(0, i); } } } }
private DateTime GetFromPeriod(IntervalPeriod periodInterval) { var currentFromInterval = HistoryDataSeries.GetTimeUtc(HistoryDataSeries.Count - 1); switch (periodInterval.Period) { case Period.Second: return(currentFromInterval > DateTime.UtcNow.AddSeconds(-periodInterval.Value) ? DateTime.UtcNow.AddSeconds(-periodInterval.Value) : currentFromInterval); case Period.Minute: return(currentFromInterval > DateTime.UtcNow.AddMinutes(-periodInterval.Value) ? DateTime.UtcNow.AddMinutes(-periodInterval.Value) : currentFromInterval); case Period.Hour: return(currentFromInterval > DateTime.UtcNow.AddHours(-periodInterval.Value) ? DateTime.UtcNow.AddHours(-periodInterval.Value) : currentFromInterval); case Period.Day: return(currentFromInterval > DateTime.UtcNow.AddDays(-periodInterval.Value) ? DateTime.UtcNow.AddDays(-periodInterval.Value) : currentFromInterval); case Period.Week: return(currentFromInterval > DateTime.UtcNow.AddDays(-periodInterval.Value * 7) ? DateTime.UtcNow.AddDays(-periodInterval.Value * 7) : currentFromInterval); case Period.Month: return(currentFromInterval > DateTime.UtcNow.AddMonths(-periodInterval.Value) ? DateTime.UtcNow.AddMonths(-periodInterval.Value) : currentFromInterval); case Period.Year: return(currentFromInterval > DateTime.UtcNow.AddYears(-periodInterval.Value) ? DateTime.UtcNow.AddYears(-periodInterval.Value) : currentFromInterval); default: return(currentFromInterval); } }
private double Close(int i = 0) { return(HistoryDataSeries.GetValue(PriceType.Close, i)); }
public override void OnPaintChart(object sender, PaintChartEventArgs args) { var winNumber = ChartSource.FindWindow(this); var winRect = ChartSource.GetAllWindows()[winNumber].WindowRectangle; args.Graphics.SetClip(winRect); var leftPoint = winRect.Location; var rightPoint = new Point(leftPoint.X + winRect.Width, leftPoint.Y); var leftTime = ChartSource.GetTimeValue(leftPoint, winNumber).TimeUtc; var rightTime = ChartSource.GetTimeValue(rightPoint, winNumber).TimeUtc; int leftOffset = HistoryDataSeries.FindInterval(leftTime); int rightOffset = HistoryDataSeries.FindInterval(rightTime); if (leftOffset == -1) { leftOffset = HistoryDataSeries.Count - 1; } if (rightOffset == -1) { rightOffset = 0; } var barWidth = ChartSource.BarsWidth; int fontSize = barWidth / 3; Font drawFont = new Font("Arial", fontSize); int counter = 1; for (int i = rightOffset; i <= leftOffset; i++) { double open = HistoryDataSeries.GetValue(PriceType.Open, i); double close = HistoryDataSeries.GetValue(PriceType.Close, i); double high = HistoryDataSeries.GetValue(PriceType.High, i); double low = HistoryDataSeries.GetValue(PriceType.Low, i); var dt = HistoryDataSeries.GetTimeUtc(i); var openPoint = ChartSource.GetChartPoint(new TimeValue(dt, open), winNumber); var closePoint = ChartSource.GetChartPoint(new TimeValue(dt, close), winNumber); var highPoint = ChartSource.GetChartPoint(new TimeValue(dt, high), winNumber); var lowPoint = ChartSource.GetChartPoint(new TimeValue(dt, low), winNumber); var lowerPoint = open < close ? openPoint : closePoint; var upperPoint = open > close ? openPoint : closePoint; var candleBodyRect = new Rectangle((int)upperPoint.X + 6, (int)upperPoint.Y, barWidth - 10, (int)lowerPoint.Y - (int)upperPoint.Y); var candleFullRect = new Rectangle((int)highPoint.X, (int)highPoint.Y, barWidth, (int)lowPoint.Y - (int)highPoint.Y); string drawString = string.Empty; int x = 0; int y = 0; float angle = 0; switch (counter) { case 1: //left vertical x = candleBodyRect.Left - (fontSize + (fontSize / 2)); // from the left edge of the candle body y = candleFullRect.Bottom; // from the bottom of the whole candle angle = -90; //draw from bottom to top drawString = "left vertical"; break; case 5: //top horizontal from center x = candleBodyRect.Left + (candleBodyRect.Width / 2); // from the left edge of the candle body, taking into account the font size y = candleFullRect.Top - (fontSize + (fontSize / 2)); // from the bottom of the whole candle drawString = "top horizontal"; break; case 9: //bottom horizontal from left edge of the whole candle x = candleFullRect.Left; // from the left edge of the whole candle body y = candleFullRect.Bottom; // from the bottom of the whole candle drawString = "bottom horizontal"; break; case 13: //center vertical from top to bootom under the whole candle x = candleBodyRect.Left + (candleBodyRect.Width / 2) + ((fontSize + (fontSize / 2)) / 2); y = candleFullRect.Bottom; angle = 90;//from top to bottom drawString = "bottom center horizontal"; break; } if (++counter > 13) { counter = 0; } if (string.IsNullOrEmpty(drawString)) { continue; } if (angle != 0) { DrawRotatedTextAt(args.Graphics, angle, drawString, drawFont, drawBrush, x, y); } else { args.Graphics.DrawString(drawString, drawFont, drawBrush, x, y); } } }
public override void Update(TickStatus args) { if (args != TickStatus.IsQuote) { if (HistoryDataSeries.Count - 1 < minRequiredBars) { return; } int leftIndex, rightIndex; double delta, tmpDelta; switch (InpLineType) { case LINE_TYPE.DELTA: //--- Support Left Point leftIndex = leftExmSide + 2; for (; !isLowestLow(leftIndex, leftExmSide) && leftIndex < HistoryDataSeries.Count - 1 - minRequiredBars; leftIndex++) { ; } curLeftSup = new TimeValue(HistoryDataSeries.GetTimeUtc(leftIndex), getLow(leftIndex)); //--- Support Right Point rightIndex = current + 2; delta = (getLow(rightIndex) - getLow(leftIndex)) / (rightIndex - leftIndex); if (!InpPrevExmBar) { leftIndex += 1; } for (int tmpIndex = rightIndex - 1; tmpIndex < leftIndex; tmpIndex++) { tmpDelta = (getLow(tmpIndex) - curLeftSup.Value) / (tmpIndex - leftIndex); if (tmpDelta > delta) { delta = tmpDelta; rightIndex = tmpIndex; } } curRightSup = new TimeValue(HistoryDataSeries.GetTimeUtc(rightIndex), getLow(rightIndex)); //--- Resistance Left Point leftIndex = leftExmSide + 2; for (; !isHighestHigh(leftIndex, leftExmSide) && leftIndex < HistoryDataSeries.Count - 1 - minRequiredBars; leftIndex++) { ; } curLeftRes = new TimeValue(HistoryDataSeries.GetTimeUtc(leftIndex), getHigh(leftIndex)); //--- Resistance Right Point rightIndex = current + 2; delta = (getHigh(leftIndex) - getHigh(rightIndex)) / (rightIndex - leftIndex); if (!InpPrevExmBar) { leftIndex += 1; } for (int tmpIndex = rightIndex - 1; tmpIndex < leftIndex; tmpIndex++) { tmpDelta = (curLeftRes.Value - getHigh(tmpIndex)) / (tmpIndex - leftIndex); if (tmpDelta > delta) { delta = tmpDelta; rightIndex = tmpIndex; } } curRightRes = new TimeValue(HistoryDataSeries.GetTimeUtc(rightIndex), getHigh(rightIndex)); break; case LINE_TYPE.EXM: default: //--- Support Right Point rightIndex = rightExmSide + 2; for (; !isLowestLow(rightIndex, rightExmSide) && rightIndex < HistoryDataSeries.Count - 1 - minRequiredBars; rightIndex++) { ; } curRightSup = new TimeValue(HistoryDataSeries.GetTimeUtc(rightIndex), getLow(rightIndex)); //--- Support Left Point leftIndex = rightIndex + leftExmSide; for (; !isLowestLow(leftIndex, leftExmSide) && leftIndex < HistoryDataSeries.Count - 1 - minRequiredBars; leftIndex++) { ; } curLeftSup = new TimeValue(HistoryDataSeries.GetTimeUtc(leftIndex), getLow(leftIndex)); //--- Resistance Right Point rightIndex = rightExmSide + 2; for (; !isHighestHigh(rightIndex, rightExmSide) && rightIndex < HistoryDataSeries.Count - 1 - minRequiredBars; rightIndex++) { ; } curRightRes = new TimeValue(HistoryDataSeries.GetTimeUtc(rightIndex), getHigh(rightIndex)); //--- Resistance Left Point leftIndex = rightIndex + leftExmSide; for (; !isHighestHigh(leftIndex, leftExmSide) && leftIndex < HistoryDataSeries.Count - 1 - minRequiredBars; leftIndex++) { ; } curLeftRes = new TimeValue(HistoryDataSeries.GetTimeUtc(leftIndex), getHigh(leftIndex)); //--- break; } } }
double getHigh(int index) { return(HistoryDataSeries.GetValue(PriceType.High, index)); }
double getLow(int index) { return(HistoryDataSeries.GetValue(PriceType.Low, index)); }
public override void OnPaintChart(object sender, PaintChartEventArgs args) { if (HistoryDataSeries.Count == 0) { return; } int winNumber = ChartSource.FindWindow(this); var winRect = ChartSource.GetAllWindows()[winNumber].WindowRectangle; args.Graphics.SetClip(winRect); var leftPoint = winRect.Location; var rightPoint = new Point(leftPoint.X + winRect.Width, leftPoint.Y); var leftTime = ChartSource.GetTimeValue(leftPoint, winNumber).TimeUtc; var rightTime = ChartSource.GetTimeValue(rightPoint, winNumber).TimeUtc; int leftOffset = HistoryDataSeries.FindInterval(leftTime); int rightOffset = HistoryDataSeries.FindInterval(rightTime); if (leftOffset == -1) { leftOffset = HistoryDataSeries.Count - 1; } if (rightOffset == -1) { rightOffset = 0; } var barWidth = ChartSource.BarsWidth; for (int i = rightOffset; i <= leftOffset; i++) { double open = Lines["Open"].GetValue(i); double high = Lines["High"].GetValue(i); double low = Lines["Low"].GetValue(i); double close = Lines["Close"].GetValue(i); var dt = HistoryDataSeries.GetTimeUtc(i); var openPoint = ChartSource.GetChartPoint(new TimeValue(dt, open), winNumber); var highPoint = ChartSource.GetChartPoint(new TimeValue(dt, high), winNumber); var lowPoint = ChartSource.GetChartPoint(new TimeValue(dt, low), winNumber); var closePoint = ChartSource.GetChartPoint(new TimeValue(dt, close), winNumber); var lowerPoint = open < close ? openPoint : closePoint; var upperPoint = open > close ? openPoint : closePoint; float middlex = lowerPoint.X + barWidth / 2; args.Graphics.DrawLine(pen, new PointF(middlex, lowPoint.Y), new PointF(middlex, lowerPoint.Y)); args.Graphics.DrawLine(pen, new PointF(middlex, highPoint.Y), new PointF(middlex, upperPoint.Y)); float decimalPart = barWidth / 10; var leftTopPoint = new PointF(upperPoint.X + decimalPart, upperPoint.Y); var rightTopPoint = new PointF(upperPoint.X + barWidth - decimalPart, upperPoint.Y); var leftBottomPoint = new PointF(lowerPoint.X + decimalPart, lowerPoint.Y); var rightBottomPoint = new PointF(lowerPoint.X + barWidth - decimalPart, lowerPoint.Y); args.Graphics.DrawLine(pen, leftTopPoint, rightTopPoint); args.Graphics.DrawLine(pen, leftBottomPoint, rightBottomPoint); args.Graphics.DrawLine(pen, leftTopPoint, leftBottomPoint); args.Graphics.DrawLine(pen, rightTopPoint, rightBottomPoint); } }
private bool isRightBorder(Exchange exchange, int i, DateTime date) { return(exchange.ExchangeDateTimeUTC(date, exchange.EndTime) <= HistoryDataSeries.GetTimeUtc(i) && exchange.ExchangeDateTimeUTC(date, exchange.EndTime) > HistoryDataSeries.GetTimeUtc(i + 1)); }
private bool isFirstOnBorder(Exchange exchange, DateTime date) { return(exchange.ExchangeDateTimeUTC(date, exchange.EndTime) >= HistoryDataSeries.GetTimeUtc(0)); }
private bool isBetweenBorder(Exchange exchange, DateTime date, int rightOffset, int leftOffset) { return(exchange.ExchangeDateTimeUTC(date, exchange.EndTime) >= HistoryDataSeries.GetTimeUtc(leftOffset) && exchange.ExchangeDateTimeUTC(date, exchange.BeginTime) <= HistoryDataSeries.GetTimeUtc(rightOffset)); }
private double HLC3(int x) { return((HistoryDataSeries.GetValue(PriceType.Close, x) + HistoryDataSeries.GetValue(PriceType.Low, x) + HistoryDataSeries.GetValue(PriceType.High, x)) / 3); }
public override void OnPaintChart(object sender, PaintChartEventArgs args) { if (!isDrawable) { return; } var gr = args.Graphics; var winNumber = ChartSource.FindWindow(this); if (winNumber != 0) { using (StringFormat format = new StringFormat()) { format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; gr.DrawString("The indicator operates only on the main chart", new Font("Arial", 24), boxBrush, args.Rectangle, format); } return; } var winRect = ChartSource.GetAllWindows()[winNumber].WindowRectangle; args.Graphics.SetClip(winRect); var leftPoint = winRect.Location; var rightPoint = new Point(leftPoint.X + winRect.Width, leftPoint.Y); var leftTime = ChartSource.GetTimeValue(leftPoint, winNumber).TimeUtc; var rightTime = ChartSource.GetTimeValue(rightPoint, winNumber).TimeUtc; var leftOffset = HistoryDataSeries.FindInterval(leftTime); var rightOffset = HistoryDataSeries.FindInterval(rightTime); if (leftOffset == -1) { leftOffset = HistoryDataSeries.Count - 1; } if (rightOffset == -1) { rightOffset = 0; } List <Exchange> properExchanges = settings.defaultExchanges; List <BoxContainer> listToDraw = fillBoxes(rightOffset, leftOffset, settings.defaultExchanges, winNumber); listToDraw.ForEach(el => { var rect = new RectangleF(el.LeftPoint.X, el.LeftPoint.Y, Math.Abs(el.LeftPoint.X - el.RightPoint.X), Math.Abs(el.LeftPoint.Y - el.RightPoint.Y)); boxPen.DashPattern = new float[] { 2, 2 }; gr.DrawRectangle(boxPen, rect.X, rect.Y, rect.Width, rect.Height); using (Brush activeBrush = new SolidBrush(el.Color)) { gr.FillRectangle(activeBrush, rect); } }); var offset = 0; listToDraw.ForEach(el => { var rect = new RectangleF(el.LeftPoint.X, el.LeftPoint.Y, Math.Abs(el.LeftPoint.X - el.RightPoint.X), Math.Abs(el.LeftPoint.Y - el.RightPoint.Y)); var midp = Midpoint(rect, offset); using (StringFormat format = new StringFormat()) { format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; gr.DrawString(el.Name, font, boxBrush, midp.X, midp.Y, format); } offset++; }); var todayDate = HistoryDataSeries.GetTimeUtc(0).Date; var tomorrowDate = HistoryDataSeries.GetTimeUtc(0).Date.AddDays(1).Date; var todayExchanges = properExchanges.FindAll(x => x.ExchangeDateTimeUTC(todayDate, x.BeginTime) > HistoryDataSeries.GetTimeUtc(0)); var tomorrowExchanges = properExchanges.FindAll(x => x.ExchangeDateTimeUTC(tomorrowDate, x.BeginTime) > HistoryDataSeries.GetTimeUtc(0)); var valueTop = ChartSource.GetTimeValue(new PointF(0, 0), winNumber).Value; var valueBottom = ChartSource.GetTimeValue(new PointF(args.Rectangle.Height, args.Rectangle.Width), winNumber).Value; offset = 0; todayExchanges.ForEach(el => { if (el.IsEnable) { var poinTop = ChartSource.GetChartPoint(new TimeValue(el.ExchangeDateTimeUTC(todayDate, el.BeginTime), valueTop), winNumber); var poinBottom = ChartSource.GetChartPoint(new TimeValue(el.ExchangeDateTimeUTC(todayDate, el.BeginTime), valueBottom), winNumber); gr.DrawLine(boxPen, poinTop, poinBottom); gr.DrawString(el.Name, font, boxBrush, poinTop.X, offset % 2 == 0 ? poinTop.Y : poinTop.Y + 20); offset++; } }); offset = 0; tomorrowExchanges.ForEach(el => { if (el.IsEnable) { var poinTop = ChartSource.GetChartPoint(new TimeValue(el.ExchangeDateTimeUTC(tomorrowDate, el.BeginTime), valueTop), winNumber); var poinBottom = ChartSource.GetChartPoint(new TimeValue(el.ExchangeDateTimeUTC(tomorrowDate, el.BeginTime), valueBottom), winNumber); gr.DrawLine(new Pen(linebrush), poinTop, poinBottom); gr.DrawString(el.Name, font, linebrush, poinTop.X, offset % 2 == 0 ? poinTop.Y + args.Rectangle.Height - 40 : poinTop.Y + args.Rectangle.Height - 60); offset++; } }); }
public override void OnPaintChart(object sender, PaintChartEventArgs args) { if (HistoryDataSeries.Count == 0) { return; } int winNumber = ChartSource.FindWindow(this); var winRect = ChartSource.GetAllWindows()[winNumber].WindowRectangle; args.Graphics.SetClip(winRect); var leftPoint = winRect.Location; var rightPoint = new Point(leftPoint.X + winRect.Width, leftPoint.Y); var leftTime = ChartSource.GetTimeValue(leftPoint, winNumber).TimeUtc; var rightTime = ChartSource.GetTimeValue(rightPoint, winNumber).TimeUtc; int leftOffset = HistoryDataSeries.FindInterval(leftTime); int rightOffset = HistoryDataSeries.FindInterval(rightTime); if (leftOffset == -1) { leftOffset = HistoryDataSeries.Count - 1; } if (rightOffset == -1) { rightOffset = 0; } var barWidth = ChartSource.BarsWidth; double previousClose = double.NaN; var previousDt = DateTime.MinValue; for (int i = rightOffset; i <= leftOffset; i++) { double close = HistoryDataSeries.GetValue(TradeApi.History.PriceType.Close, i); var dt = HistoryDataSeries.GetTimeUtc(i); if (double.IsNaN(previousClose)) { previousClose = close; previousDt = dt; continue; } if (previousDt == dt || Math.Abs((previousClose - close) / close) < _priceChangeLimit / 100) { continue; } var previousClosePoint = ChartSource.GetChartPoint(new TimeValue(previousDt, previousClose), winNumber); var nextClosePoint = ChartSource.GetChartPoint(new TimeValue(dt, close), winNumber); args.Graphics.DrawLine(_pen, new PointF(previousClosePoint.X + barWidth / 2, previousClosePoint.Y), new PointF(nextClosePoint.X + barWidth / 2, nextClosePoint.Y)); previousClose = close; previousDt = dt; } }
private double High(int i) { return(HistoryDataSeries.GetValue(PriceType.High, i)); }
private double Low(int i) { return(HistoryDataSeries.GetValue(PriceType.Low, i)); }
private double Open(int i = 0) { return(HistoryDataSeries.GetValue(PriceType.Open, i)); }