internal CandlestickChart(string file, string sheet, string topLeftCorner, string bottomRightCorner, int timerInterval, int slowLength, ILevel1 level1, TextBox box) { _level1 = level1; _lastVolume = _level1.Volume; Candlesticks = new List <Candlestick>(); var excelApp = new Excel.Application { Visible = true }; var excelWorkbook = excelApp.Workbooks.Open(file, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); var excelSheets = excelWorkbook.Worksheets; var excelWorksheet = (Excel.Worksheet)excelSheets.Item[sheet]; //notice the cell numbers, change them as required var excelRange = excelWorksheet.Range[topLeftCorner, bottomRightCorner]; for (var i = 1; i <= slowLength; ++i) { Candlesticks.Add(new Candlestick() { IsNull = false, High = (decimal)((Excel.Range)excelRange.Cells[i, 1]).Value2, Low = (decimal)((Excel.Range)excelRange.Cells[i, 3]).Value2, Open = (decimal)((Excel.Range)excelRange.Cells[i, 4]).Value2, Close = (decimal)((Excel.Range)excelRange.Cells[i, 2]).Value2 }); } excelRange = excelWorksheet.Range["Y2", "Y2"]; MarketConditionCoefficient = (decimal)((Excel.Range)excelRange.Cells[1, 1]).Value2; excelWorkbook.Close(); excelApp.Quit(); ReleaseObject(excelWorksheet); ReleaseObject(excelWorkbook); ReleaseObject(excelApp); Candlesticks.Reverse(); CurrentCandlestick = new Candlestick(); //Set up timer _timer = new Timer { Interval = timerInterval, Enabled = false, AutoReset = true }; _timer.Elapsed += TimerOnTick; }
private void TimerOnTick(object sender, EventArgs eventArgs) { if (!CurrentCandlestick.IsNull) { Candlesticks.Add(CurrentCandlestick); } CurrentCandlestick = new Candlestick(); }