//Bar udpates public void BarUpdate(string Symbol, M4.DataServer.Interface.Periodicity BarType, int BarSize, M4.DataServer.Interface.BarData Bar, bool IsNewBar) { if (m_stop) { return; } Alert oAlert = GetTSAlertObject(Symbol); if (oAlert == null) { return; // Not watching this symbol } double jdate = 0, o = 0, h = 0, l = 0, c = 0; int v = 0; if (!oAlert.GetRecordByIndex(oAlert.RecordCount, ref jdate, ref o, ref h, ref l, ref c, ref v)) { return; } if (IsNewBar) { // Append new bar double jDate = oAlert.ToJulianDate(Bar.TradeDate.Year, Bar.TradeDate.Month, Bar.TradeDate.Day, Bar.TradeDate.Hour, Bar.TradeDate.Minute, Bar.TradeDate.Second, Bar.TradeDate.Millisecond); oAlert.AppendRecord(jDate, Bar.OpenPrice, Bar.HighPrice, Bar.LowPrice, Bar.ClosePrice, (int)Bar.VolumeF); } else { // Edit existing bar oAlert.EditRecord(jdate, Bar.OpenPrice, Bar.HighPrice, Bar.LowPrice, Bar.ClosePrice, (int)Bar.VolumeF); } //Update the DataGridView DataGridViewRow row = m_DGVRowDictionary[Symbol]; if (row != null) { row.Cells["Trade Time"].Value = m_TimeStamp; row.Cells["Last"].Value = Format.ToUsCurrency(Bar.ClosePrice); row.Cells["Volume"].Value = Format.ToLocalInteger((int)Bar.VolumeF); } }
public BarDataEventArgs(BarData bar) { Bar = bar; }
//Loads all required data into memory. This function must be called first. public bool LoadAllSymbolsIntoMemory() { //Verify the input and check script for errors if (m_ctlData == null || !TestScripts()) { return(false); } EnableControls(false); //Clear everything m_stop = false; m_TSAlertDictionary.Clear(); m_DGVRowDictionary.Clear(); grdResults.Rows.Clear(); DataGridViewBarGraphColumn volumeCol = (DataGridViewBarGraphColumn)grdResults.Columns["Volume"]; if (volumeCol != null) { volumeCol.MaxValue = 0; } //Load history for all symbols into memory pnlProgress.Cursor = Cursors.WaitCursor; pnlProgress.Visible = true; if (Symbols.Count > 1) { ProgressBar1.Maximum = Symbols.Count - 1; } ChartSelection selection = new ChartSelection { Periodicity = (M4Core.Entities.Periodicity)Periodicity, Interval = Interval, Bars = Bars * 3 }; if (selection.Bars < 50) { selection.Bars = 50; } lblInfo.Text = "Priming scanner, please wait..."; for (int n = 0; n < Symbols.Count; n++) { string symbol = Symbols[n]; if (m_stop) { break; } if (m_TSAlertDictionary.ContainsKey(symbol)) { continue; } selection.Symbol = symbol; ProgressBar1.Value = n; lblSymbol.Text = symbol; Application.DoEvents(); //Get historic data var bars = m_ctlData.GetHistory(symbol, this, selection.Periodicity, selection.Interval, selection.Bars, "Plena", answer => { }); if (bars == null || bars.Count < 3) { continue; } //Insert the data into TradeScript Alert oAlert = new Alert { License = "XRT93NQR79ABTW788XR48" }; foreach (M4.DataServer.Interface.BarData t in bars) { double jDate = oAlert.ToJulianDate(t.TradeDate.Year, t.TradeDate.Month, t.TradeDate.Day, t.TradeDate.Hour, t.TradeDate.Minute, t.TradeDate.Second, t.TradeDate.Millisecond); oAlert.AppendHistoryRecord(jDate, t.OpenPrice, t.HighPrice, t.LowPrice, t.ClosePrice, (int)t.VolumeF); } //Start the alert object by adding the script oAlert.AlertScript = Script; oAlert.Symbol = symbol; oAlert.ScriptError += oScript_ScriptError; oAlert.Alert += OnAlert; m_TSAlertDictionary.Add(symbol, oAlert); //Add symbol to datagridview int row; try { row = grdResults.Rows.Add(new DataGridViewRow()); } catch (Exception) { return(false); } m_DGVRowDictionary.Add(symbol, grdResults.Rows[row]); grdResults.Rows[row].Height = 25; M4.DataServer.Interface.BarData lastBar = bars.Last(); DataGridViewTextBoxScannerColorCell alertDateTime = (DataGridViewTextBoxScannerColorCell)grdResults.Rows[row].Cells["Alert Time"]; alertDateTime.HighlightOnly = true; alertDateTime.Value = lastBar.TradeDate; alertDateTime.Interval = 5000; grdResults.Rows[row].Cells["Trade Time"].Value = lastBar.TradeDate; grdResults.Rows[row].Cells["Symbol"].Value = symbol; grdResults.Rows[row].Cells["Last"].Value = Format.ToUsCurrency(lastBar.ClosePrice); grdResults.Rows[row].Cells["Volume"].Value = Format.ToLocalInteger((int)lastBar.VolumeF); DataGridViewButtonCell button = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Trade"]; button.Value = "Trade"; button.FlatStyle = FlatStyle.Flat; button = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Chart"]; button.Value = "Chart"; button.FlatStyle = FlatStyle.Flat; button = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Settings"]; button.Value = "Settings"; button.FlatStyle = FlatStyle.Flat; button = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Start"]; button.Value = "Start"; button.FlatStyle = FlatStyle.Flat; DataGridViewImageButtonCell start = (DataGridViewImageButtonCell)grdResults.Rows[row].Cells["Start"]; start.ImageOn = Resources.Play; start.ImageOff = Resources.Pause; start.OffsetY = 4; DataGridViewImageButtonCell @lock = (DataGridViewImageButtonCell)grdResults.Rows[row].Cells["Locked"]; @lock.ImageOn = Resources.Lock; @lock.ImageOff = Resources.Unlock; @lock.OffsetY = 2; } lblInfo.Text = string.Empty; pnlProgress.Visible = false; pnlProgress.Cursor = Cursors.Arrow; EnableControls(true); return(true); }