Downloading history
Using historical data for indicator or strategy calculations
IHistoricalData historicalData = Symbol.GetHistory(Period.MIN15, HistoryType.Bid, new DateTime(2018, 8, 1, 0, 0, 0, DateTimeKind.Utc), new DateTime(2018, 8, 31, 0, 0, 0, DateTimeKind.Utc));IHistoricalData historicalData = Symbol.GetHistory(Period.MIN15, HistoryType.Bid, DateTime.UtcNow.AddDays(-1));IHistoricalData historicalData = Symbol.GetHistory(Period.MIN15, HistoryType.Bid, DateTime.UtcNow.AddDays(-1));double openPrice = ((HistoryItemBar)historicalData[0]).Open;double closePrice = ((HistoryItemBar)historicalData[0]).Close;double volume = ((HistoryItemBar)historicalData[0]).Volume;DateTime leftBorderOfBar = ((HistoryItemBar)historicalData[0]).TimeLeft;IHistoricalData historicalData = Symbol.GetHistory(Period.TICK1, HistoryType.Bid, DateTime.UtcNow.AddDays(-1));double bidPrice = ((HistoryItemTick)historicalData[0]).Bid;double askPrice = ((HistoryItemTick)historicalData[0]).Ask;Indicator sma5MinCurrent;Indicator sma15MinMainCurrent;Indicator sma30MinMainCurrent;Indicator sma5MinAdditional;Indicator sma15MinAdditional;Indicator sma30MinAdditional;[InputParameter()]Symbol AdditionalSymbol;protected override void OnInit(){ IHistoricalData data5MinCurrent = this.Symbol.GetHistory(Period.MIN5, HistoryType.Bid, DateTime.UtcNow.AddDays(-1)); data5MinCurrent.AddIndicator(sma5MinCurrent = Core.Indicators.BuiltIn.SMA(10, PriceType.Close)); IHistoricalData data15MinCurrent = this.Symbol.GetHistory(Period.MIN15, HistoryType.Bid, DateTime.UtcNow.AddDays(-1)); data15MinCurrent.AddIndicator(sma15MinMainCurrent = Core.Indicators.BuiltIn.SMA(10, PriceType.Close)); IHistoricalData data30MinCurrent = this.Symbol.GetHistory(Period.MIN30, HistoryType.Bid, DateTime.UtcNow.AddDays(-1)); data30MinCurrent.AddIndicator(sma30MinMainCurrent = Core.Indicators.BuiltIn.SMA(10, PriceType.Close)); if (AdditionalSymbol != null) { IHistoricalData data5MinAdditional = this.AdditionalSymbol.GetHistory(Period.MIN5, HistoryType.Bid, DateTime.UtcNow.AddDays(-1)); data5MinAdditional.AddIndicator(sma5MinAdditional = Core.Indicators.BuiltIn.SMA(10, PriceType.Close)); IHistoricalData data15MinAdditional = this.AdditionalSymbol.GetHistory(Period.MIN15, HistoryType.Bid, DateTime.UtcNow.AddDays(-1)); data15MinAdditional.AddIndicator(sma15MinAdditional = Core.Indicators.BuiltIn.SMA(10, PriceType.Close)); IHistoricalData data30MinAdditional = this.AdditionalSymbol.GetHistory(Period.MIN30, HistoryType.Bid, DateTime.UtcNow.AddDays(-1)); data30MinAdditional.AddIndicator(sma30MinAdditional = Core.Indicators.BuiltIn.SMA(10, PriceType.Close)); }}public override void OnPaintChart(PaintChartEventArgs args){ Graphics gr = Graphics.FromHdc(args.Hdc); Font f = new Font("Arial", 10); gr.DrawString(this.Symbol.Name, new Font(f, FontStyle.Underline), Brushes.LightCoral, 10, 35); gr.DrawString("SMA 5Min: " + this.Symbol.FormatPrice(sma5MinCurrent.GetValue()), f, Brushes.LightCoral, 10, 55); gr.DrawString("SMA 15Min: " + this.Symbol.FormatPrice(sma15MinMainCurrent.GetValue()), f, Brushes.LightCoral, 10, 75); gr.DrawString("SMA 30Min: " + this.Symbol.FormatPrice(sma30MinMainCurrent.GetValue()), f, Brushes.LightCoral, 10, 95); if (this.AdditionalSymbol != null) { gr.DrawString(this.AdditionalSymbol.Name, new Font(f, FontStyle.Underline), Brushes.LightGreen, 160, 35); gr.DrawString("SMA 5Min: " + this.AdditionalSymbol.FormatPrice(sma5MinAdditional.GetValue()), f, Brushes.LightGreen, 160, 55); gr.DrawString("SMA 15Min: " + this.AdditionalSymbol.FormatPrice(sma15MinAdditional.GetValue()), f, Brushes.LightGreen, 160, 75); gr.DrawString("SMA 30Min: " + this.AdditionalSymbol.FormatPrice(sma30MinAdditional.GetValue()), f, Brushes.LightGreen, 160, 95); }}
Last updated
Was this helpful?