static public void InsertTradeLog(Trade TradeObject) { try { AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString; TradeLog l = new TradeLog { Time = TradeObject.TimeStamp, BuySell = TradeObject.BuyorSell.ToString(), Reason = TradeObject.Reason.ToString(), Notes = TradeObject.IndicatorNotes.ToString(), Price = (int)TradeObject.TradedPrice, Volume = TradeObject.TradeVolume, ForeColor = TradeObject.ForeColor.ToKnownColor().ToString(), BackColor = TradeObject.BackColor.ToKnownColor().ToString() }; dc.TradeLogs.InsertOnSubmit(l); dc.SubmitChanges(); } catch (Exception ex) { Debug.WriteLine("Cannot write Log"); Debug.WriteLine(ex.Message); } }
private void TickDataToXMinData() { AlsiUtils.AlsiDBDataContext dc = new AlsiDBDataContext(); switch (_Interval) { case GlobalObjects.TimeInterval.Minute_2: break; case GlobalObjects.TimeInterval.Minute_5: dc.OHLC_5_Temp(); break; case GlobalObjects.TimeInterval.Minute_10: break; } GlobalObjects.Points.Clear(); foreach (var p in dc.OHLC_Temps) { var P = new Price() { TimeStamp = p.Stamp, Open = p.O, High = p.H, Low = p.L, Close = p.C, InstrumentName = _ContractName, }; GlobalObjects.Points.Add(P); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsCallback) { //http://www.codeproject.com/articles/432860/asp-net-plotter-toolkit-html5-charting-for-all AlsiDBDataContext dc = new AlsiDBDataContext(); var data = dc.OHLC_5_Minutes.Take(25000).ToList(); Label1.Text = data.Count.ToString(); Curve curve = new Curve(); var points = new Point[data.Count]; for (int x = 0; x < data.Count; x++) { var p = new Point(data[x].Stamp, data[x].C); points[x] = p; } BindingList<Curve> Curves = new BindingList<Curve> { curve }; curve.Points = points; curve.Label = "Dfdfdfdff"; Dygraph1.Curves = Curves; Dygraph1.YLowRange = data.Min(z => z.C);//if error check db Dygraph1.YHighRange = data.Max(z => z.C); } }
public static void DoYourThing_absoluut(string Instrument) { var webMinData = HiSat.HistData.GetHistoricalMINUTE_FromWEB(DateTime.Now.AddDays(-10), DateTime.Now, 1, Instrument); var webMinDataOriginal = new List <Price>(); foreach (var t in webMinData) { Price p = (Price)t.Clone(); webMinDataOriginal.Add(p); } //get last price from web var L = webMinData.Last(); Debug.WriteLine("Remove LAST Price from WebData" + L.TimeStamp + " " + L.Close); //remove last price if there was a trade since update started Price pt = (Price)L.Clone(); pt.Close = 33333; pt.TimeStamp = pt.TimeStamp.AddMinutes(1); webMinData.Add(pt); //check price if (GetTimestampForPrice(webMinData.Last())) { webMinData.Remove(L); } var l = webMinData.Last(); Debug.WriteLine("New LAST Price from WebData " + l.TimeStamp + " " + l.Close); var Loriginal = webMinDataOriginal.Last(); Debug.WriteLine("New LAST Price from Original " + Loriginal.TimeStamp + " " + Loriginal.Close); var dc = new AlsiUtils.AlsiDBDataContext(); var TickData = dc.RawTicks.ToList().Where(z => z.Stamp >= webMinData.Last().TimeStamp).ToList(); foreach (var v in convertTickToMinute(TickData)) { if (v.TimeStamp > l.TimeStamp) { // webMinData.Add(v); // Debug.WriteLine("Adding New Price " + v.TimeStamp + " " + l.Close); } } UpdateDB._1MinDataToImportMinute(webMinData); }
private void BulkInsert() { #region Create Data Table in Memory DataTable RawTicks = new DataTable("TickData"); //RawTicks.Columns.Add("N", typeof(int)); RawTicks.Columns.Add("Stamp", typeof(DateTime)); RawTicks.Columns.Add("O", typeof(int)); RawTicks.Columns.Add("H", typeof(int)); RawTicks.Columns.Add("L", typeof(int)); RawTicks.Columns.Add("C", typeof(int)); RawTicks.Columns.Add("V", typeof(int)); RawTicks.Columns.Add("Instrument", typeof(string)); insertBW.ReportProgress(60); #endregion #region Populate data Table foreach (Price p in AllHisto) RawTicks.Rows.Add(p.TimeStamp, p.Open, p.High, p.Low, p.Close, p.Volume, p.InstrumentName); insertBW.ReportProgress(70); #endregion #region Clear SQl Table // currentTaskStatusLabel.Text = "Writing to Data Base"; //PC string ccc = @"Data Source=ALSI-PC\;Initial Catalog=AlsiTrade;Integrated Security=True"; AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString = ccc; AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = ccc; // dc.CleanTick(); #endregion #region Bulk copy to SQL DataSet tickDataSet = new DataSet("AllTicks"); tickDataSet.Tables.Add(RawTicks); SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString =ccc; myConnection.Open(); SqlBulkCopy bulkcopy = new SqlBulkCopy(myConnection); bulkcopy.BulkCopyTimeout = 10000000; bulkcopy.DestinationTableName = "ImportMinute"; bulkcopy.WriteToServer(RawTicks); //Debug.WriteLine("Ticks Written To DATASET " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); insertBW.ReportProgress(100); #endregion #region Cleanup RawTicks.Dispose(); myConnection.Close(); //dc.CleanUp(); #endregion }
public static void DoYourThing_absoluut(string Instrument) { var webMinData = HiSat.HistData.GetHistoricalMINUTE_FromWEB(DateTime.Now.AddDays(-10), DateTime.Now, 1, Instrument); var webMinDataOriginal = new List<Price>(); foreach (var t in webMinData) { Price p = (Price)t.Clone(); webMinDataOriginal.Add(p); } //get last price from web var L = webMinData.Last(); Debug.WriteLine("Remove LAST Price from WebData" + L.TimeStamp + " " + L.Close); //remove last price if there was a trade since update started Price pt = (Price)L.Clone(); pt.Close = 33333; pt.TimeStamp = pt.TimeStamp.AddMinutes(1); webMinData.Add(pt); //check price if (GetTimestampForPrice(webMinData.Last())) webMinData.Remove(L); var l = webMinData.Last(); Debug.WriteLine("New LAST Price from WebData " + l.TimeStamp + " " + l.Close); var Loriginal = webMinDataOriginal.Last(); Debug.WriteLine("New LAST Price from Original " + Loriginal.TimeStamp + " " + Loriginal.Close); var dc = new AlsiUtils.AlsiDBDataContext(); var TickData = dc.RawTicks.ToList().Where(z => z.Stamp >= webMinData.Last().TimeStamp).ToList(); foreach (var v in convertTickToMinute(TickData)) if (v.TimeStamp > l.TimeStamp) { // webMinData.Add(v); // Debug.WriteLine("Adding New Price " + v.TimeStamp + " " + l.Close); } UpdateDB._1MinDataToImportMinute(webMinData); }
/// <summary> /// Full DataBase Update from Webdata /// </summary> /// <param name="ContractName">Contract name : example "DEC12ALSI"</param> /// <param name="CustomConnectionString">Custom Connection String, this will set Current Connection String</param> public static void FullHistoricUpdate_MasterMinute(string ContractName) { AlsiDBDataContext dc = new AlsiDBDataContext(); var dateL = dc.MasterMinutes.AsEnumerable().Where(z => z.Instrument == ContractName); if (dateL.Count() == 0) throw new Exception("Contract name has no match in database.\n" + ContractName + " cannot be found"); DateTime Last = dateL.Last().Stamp; DateTime Now = DateTime.UtcNow.AddHours(2); GlobalObjects.Points.Clear(); GlobalObjects.Points = HiSat.HistData.GetHistoricalMINUTE_FromWEB(Last, Now, 1, ContractName); UpdatePricesToImportMinute(); }
public static void MergeTempWithHisto(GlobalObjects.TimeInterval T) { var dc = new AlsiDBDataContext(); switch (T) { case (GlobalObjects.TimeInterval.Minute_5): //Must be 2000 prices in db for accurate calcs if (dc.OHLC_5_Minutes.Count() < 20100) throw new IndexOutOfRangeException(); var last1000Prices = dc.OHLC_5_Minutes.Skip(Math.Max(0, dc.OHLC_5_Minutes.Count() - 20000)).Take(20000); dc.Clean_OHLC_Temp_2(); DataTable MinData = new DataTable("MinData"); MinData.Columns.Add("Stamp", typeof(DateTime)); MinData.Columns.Add("O", typeof(int)); MinData.Columns.Add("L", typeof(int)); MinData.Columns.Add("H", typeof(int)); MinData.Columns.Add("C", typeof(int)); foreach (var p in last1000Prices) MinData.Rows.Add(p.Stamp, p.O, p.H, p.L, p.C); #region BulkCopy DataSet minuteDataSet = new DataSet("minuteDataset"); minuteDataSet.Tables.Add(MinData); SqlConnection myConnection = new SqlConnection(AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString); myConnection.Open(); SqlBulkCopy bulkcopy = new SqlBulkCopy(myConnection); bulkcopy.DestinationTableName = "OHLC_Temp_2"; bulkcopy.WriteToServer(MinData); Debug.WriteLine("Tick Bulk Copy Complete"); MinData.Dispose(); myConnection.Close(); #endregion dc.MergeTemp(); Debug.WriteLine("Merged Data"); break; } }
public static bool TestSqlConnection(string CCS, out string Error) { bool alive = true; try { AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString = CCS; AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = CCS; dc.Connection.Open(); Error = ""; } catch(Exception ex) { alive = false; Error = ex.Message; } return alive; }
public static void UpdatePricesToImportMinute() { AlsiDBDataContext dc = new AlsiDBDataContext(); dc.ClearImportTable(); dc.Clean_OHLC_Temp(); DataTable MinData = new DataTable("MinData"); MinData.Columns.Add("Stamp", typeof(DateTime)); MinData.Columns.Add("O", typeof(int)); MinData.Columns.Add("L", typeof(int)); MinData.Columns.Add("H", typeof(int)); MinData.Columns.Add("C", typeof(int)); MinData.Columns.Add("V", typeof(int)); MinData.Columns.Add("Instrument", typeof(string)); foreach (var p in GlobalObjects.Points) MinData.Rows.Add(p.TimeStamp, p.Open, p.High, p.Low, p.Close, p.Volume, p.InstrumentName); #region BulkCopy DataSet minuteDataSet = new DataSet("minuteDataset"); minuteDataSet.Tables.Add(MinData); SqlConnection myConnection = new SqlConnection(AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString); myConnection.Open(); SqlBulkCopy bulkcopy = new SqlBulkCopy(myConnection); bulkcopy.DestinationTableName = "ImportMinute"; bulkcopy.WriteToServer(MinData); Debug.WriteLine("Tick Bulk Copy Complete"); MinData.Dispose(); myConnection.Close(); #endregion dc.UpadteImport(); dc.CleanUp(); }
public static void _1MinDataToImportMinute(List <Price> MinutePrices) { var dc = new AlsiUtils.AlsiDBDataContext(); dc.ClearImportTable(); dc.Clean_OHLC_Temp(); DataTable MinData = new DataTable("MinData"); MinData.Columns.Add("Stamp", typeof(DateTime)); MinData.Columns.Add("O", typeof(int)); MinData.Columns.Add("L", typeof(int)); MinData.Columns.Add("H", typeof(int)); MinData.Columns.Add("C", typeof(int)); MinData.Columns.Add("V", typeof(int)); foreach (var p in MinutePrices) { MinData.Rows.Add(p.TimeStamp, p.Open, p.High, p.Low, p.Close, p.Volume); } #region BulkCopy DataSet minuteDataSet = new DataSet("minuteDataset"); minuteDataSet.Tables.Add(MinData); SqlConnection myConnection = new SqlConnection(AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString); myConnection.Open(); SqlBulkCopy bulkcopy = new SqlBulkCopy(myConnection); bulkcopy.DestinationTableName = "ImportMinute"; bulkcopy.WriteToServer(MinData); Debug.WriteLine("Tick Bulk Copy Complete"); MinData.Dispose(); myConnection.Close(); #endregion }
private void LoadTradeLog(bool todayOnly, bool onlyTrades, int periods) { AlsiDBDataContext dc = new AlsiDBDataContext(); liveTradeListView.Items.Clear(); IQueryable<AlsiUtils.TradeLog> tl = null; int count = dc.TradeLogs.Count(); if (periods > count) return; if (todayOnly) { if (onlyTrades) { tl = from x in dc.TradeLogs where x.Time == DateTime.Now.Date where x.BuySell != "None" select x; } else { tl = from x in dc.TradeLogs where x.Time == DateTime.Now.Date select x; } } else { if (onlyTrades) { tl = (from x in dc.TradeLogs select x).Skip(count - periods); tl = tl.Where(z => z.BuySell != "None"); } else { tl = (from x in dc.TradeLogs select x).Skip(count - periods); } } liveTradeListView.BeginUpdate(); Cursor = Cursors.WaitCursor; foreach (var v in tl) { Trade t = new Trade() { TimeStamp = v.Time, TradeVolume = (int)v.Volume, BuyorSell = Trade.BuySellFromString(v.BuySell), IndicatorNotes = v.Notes, CurrentPrice = (double)v.Price, ForeColor = Color.FromName(v.ForeColor), BackColor = Color.FromName(v.BackColor), Reason = GetTradeReasonFromString(v.Reason), }; UpdateTradeLog(t, false); } liveTradeListView.EndUpdate(); Cursor = Cursors.Default; }
public static void ClearTradeLog() { var dc = new AlsiDBDataContext(); var delAll = dc.TradeLogs; dc.TradeLogs.DeleteAllOnSubmit(delAll); dc.SubmitChanges(); }
public static void TickBulkCopy(string InstrumentName, DateTime Start) { DateTime _start = DateTime.Now.AddDays(-10); DateTime UseThisDate = Start > _start ? _start : Start; AlsiDBDataContext dc = new AlsiDBDataContext(); var tickData = HistData.GetHistoricalTICK_FromWEB(_start, DateTime.UtcNow.AddHours(2), InstrumentName); DataTable RawTicks = new DataTable("TickData"); RawTicks.Columns.Add("N", typeof(long)); RawTicks.Columns.Add("Stamp", typeof(DateTime)); RawTicks.Columns.Add("Price", typeof(int)); foreach (var p in tickData) RawTicks.Rows.Add(1, p.TimeStamp, p.Close); dc.CleanTick(); #region BulkCopy DataSet tickDataSet = new DataSet("AllTicks"); tickDataSet.Tables.Add(RawTicks); SqlConnection myConnection = new SqlConnection(AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString); myConnection.Open(); SqlBulkCopy bulkcopy = new SqlBulkCopy(myConnection); bulkcopy.DestinationTableName = "RawTick"; bulkcopy.WriteToServer(RawTicks); Debug.WriteLine("Tick Bulk Copy Complete"); RawTicks.Dispose(); myConnection.Close(); dc.CleanUp(); #endregion }
static public List<Price> readDataFromDataBase_1_MIN_MasterMinute(int numberOfPeriods, bool reverseList) { try { List<Price> prices = new List<Price>(); AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString; var count = (from p in dc.MasterMinutes select (p.Stamp)).Count(); //Console.WriteLine("10 Minute Data Count : " + count); var result = from q in dc.MasterMinutes .Skip(count - numberOfPeriods) .Take(numberOfPeriods) select new { q.Stamp, q.O, q.H, q.L, q.C, q.Instrument }; foreach (var v in result) { Price p = new Price(); p.Close = v.C; p.Open = v.O; p.High = v.H; p.Low = v.L; p.TimeStamp = v.Stamp; p.InstrumentName = v.Instrument; prices.Add(p); } if (reverseList) prices.Reverse(); return prices; } catch (Exception ex) { Debug.WriteLine("readDataFromDataBase_10_MIN Database Busy : " + ex.Message); return null; } }
private void AllHistoRadioButton_CheckedChanged(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; if (allhistoStart.Year == 1) { AlsiDBDataContext dc = new AlsiDBDataContext(); allhistoStart = dc.AllHistoricMinutes.AsEnumerable().First().Stamp; allhistoEnd = dc.AllHistoricMinutes.AsEnumerable().Last().Stamp; startDateTimePicker.MinDate = allhistoStart; endDateTimePicker.MaxDate = allhistoEnd; startDateTimePicker.Refresh(); endDateTimePicker.Refresh(); } if (AllHistoRadioButton.Checked) { startDateTimePicker.MinDate = allhistoStart; endDateTimePicker.MaxDate = allhistoEnd; startDateTimePicker.Refresh(); endDateTimePicker.Refresh(); } Cursor = Cursors.Default; }
private void recentRadioButton_CheckedChanged(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; if (masterStart.Year == 1) { AlsiDBDataContext dc = new AlsiDBDataContext(); masterStart = dc.MasterMinutes.AsEnumerable().First().Stamp; masterEnd = dc.MasterMinutes.AsEnumerable().Last().Stamp; startDateTimePicker.MinDate = masterStart; endDateTimePicker.MaxDate = masterEnd; startDateTimePicker.Refresh(); endDateTimePicker.Refresh(); } if (recentRadioButton.Checked) { startDateTimePicker.MinDate = masterStart; endDateTimePicker.MaxDate = masterEnd; if (startDateTimePicker.Value < masterStart) startDateTimePicker.Value = masterStart; startDateTimePicker.Refresh(); endDateTimePicker.Refresh(); } Cursor = Cursors.Default; }
private void UpdateAllHistoPrices_Click(object sender, EventArgs e) { masterStart = new DateTime(); allhistoStart = new DateTime(); Cursor = Cursors.WaitCursor; AlsiDBDataContext dc = new AlsiDBDataContext(); dc.UpadteAllHistory(); Cursor = Cursors.Default; }
static public List<Price> readDataFromDataBase(GlobalObjects.TimeInterval T, dataTable TD, DateTime Start, DateTime End, bool reverseList) { List<Price> prices = new List<Price>(); AlsiDBDataContext dc = new AlsiDBDataContext(); if (TD == dataTable.Temp) { var result = from q in dc.OHLC_Temps where q.Stamp > Start && q.Stamp < End select new { q.Stamp, q.O, q.H, q.L, q.C, }; foreach (var v in result) { Price p = new Price(); p.Close = v.C; p.Open = v.O; p.High = v.H; p.Low = v.L; p.TimeStamp = v.Stamp; prices.Add(p); } dc.Clean_OHLC_Temp(); if (reverseList) prices.Reverse(); return prices; } if (TD == dataTable.AllHistory) { if (T == GlobalObjects.TimeInterval.Minute_2) { var firstinDB = dc.OHLC_2_Minutes.AsEnumerable().First().Stamp; var lastinDB = dc.OHLC_2_Minutes.AsEnumerable().Last().Stamp; if (firstinDB > Start) dc.OHLC_2_AllHistory(); if (lastinDB > End) dc.OHLC_2_AllHistory(); } if (T == GlobalObjects.TimeInterval.Minute_5) { try { var firstinDB = dc.OHLC_5_Minutes.AsEnumerable().First().Stamp; var lastinDB = dc.OHLC_5_Minutes.AsEnumerable().Last().Stamp; if (firstinDB > Start) dc.OHLC_5_AllHistory(); if (lastinDB < End) dc.OHLC_5_AllHistory(); } catch { dc.OHLC_5_AllHistory(); } } if (T == GlobalObjects.TimeInterval.Minute_10) { var firstinDB = dc.OHLC_10_Minutes.AsEnumerable().First().Stamp; var lastinDB = dc.OHLC_10_Minutes.AsEnumerable().Last().Stamp; if (firstinDB > Start) dc.OHLC_10_AllHistory(); if (lastinDB < End) dc.OHLC_10_AllHistory(); } } if (TD == dataTable.MasterMinute) { if (T == GlobalObjects.TimeInterval.Minute_2) { var min2 = dc.OHLC_2_Minutes; if (min2.Count() == 0) { dc.OHLC_2(); } else { var firstinDB = dc.OHLC_2_Minutes.AsEnumerable().First().Stamp; var lastinDB = dc.OHLC_2_Minutes.AsEnumerable().Last().Stamp; if (firstinDB > Start) dc.OHLC_2(); if (lastinDB < End) dc.OHLC_2(); } } if (T == GlobalObjects.TimeInterval.Minute_5) { var min5 = dc.OHLC_5_Minutes; if (min5.Count() == 0) { dc.OHLC_5(); } else { var firstinDB = min5.AsEnumerable().First().Stamp; var lastinDB = min5.AsEnumerable().Last().Stamp; if (firstinDB > Start) dc.OHLC_5(); if (lastinDB < End) dc.OHLC_5(); } } if (T == GlobalObjects.TimeInterval.Minute_10) { var min10 = dc.OHLC_10_Minutes; if (min10.Count() == 0) { dc.OHLC_10(); } else { var firstinDB = dc.OHLC_10_Minutes.AsEnumerable().First().Stamp; var lastinDB = dc.OHLC_10_Minutes.AsEnumerable().Last().Stamp; if (firstinDB > Start) dc.OHLC_10(); if (lastinDB < End) dc.OHLC_10(); } } if (T == GlobalObjects.TimeInterval.Hour_1) { dc.OHLC_Hour_1(); } } if (T == GlobalObjects.TimeInterval.Minute_2) { var result = from q in dc.OHLC_2_Minutes where q.Stamp > Start && q.Stamp < End select new { q.Stamp, q.O, q.H, q.L, q.C, q.Instrument }; foreach (var v in result) { Price p = new Price(); p.Close = v.C; p.Open = v.O; p.High = v.H; p.Low = v.L; p.TimeStamp = v.Stamp; p.InstrumentName = v.Instrument; prices.Add(p); } } if (T == GlobalObjects.TimeInterval.Minute_5) { var result = from q in dc.OHLC_5_Minutes where q.Stamp > Start && q.Stamp < End select new { q.Stamp, q.O, q.H, q.L, q.C, q.Instrument }; foreach (var v in result) { Price p = new Price(); p.Close = v.C; p.Open = v.O; p.High = v.H; p.Low = v.L; p.TimeStamp = v.Stamp; p.InstrumentName = v.Instrument; prices.Add(p); } } if (T == GlobalObjects.TimeInterval.Minute_10) { var result = from q in dc.OHLC_10_Minutes where q.Stamp > Start && q.Stamp < End select new { q.Stamp, q.O, q.H, q.L, q.C, q.Instrument }; foreach (var v in result) { Price p = new Price(); p.Close = v.C; p.Open = v.O; p.High = v.H; p.Low = v.L; p.TimeStamp = v.Stamp; p.InstrumentName = v.Instrument; prices.Add(p); } } if (T == GlobalObjects.TimeInterval.Hour_1) { var result = from q in dc.OHLC_1_Hours where q.Stamp > Start && q.Stamp < End select new { q.Stamp, q.O, q.H, q.L, q.C, q.Instrument }; foreach (var v in result) { Price p = new Price(); p.Close = v.C; p.Open = v.O; p.High = v.H; p.Low = v.L; p.TimeStamp = v.Stamp; p.InstrumentName = v.Instrument; prices.Add(p); } } if (reverseList) prices.Reverse(); return prices; }
static public void get_10min_high_low_from_ticks(out double High, out double Low) { try { //get 10 min high AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString; var last = (from q in dc.OHLC_10_Minutes orderby q.Stamp descending select new { q.Stamp, q.L }).Take(2); List<DateTime> dt = new List<DateTime>(); foreach (var v in last) { dt.Add(v.Stamp); //Debug.WriteLine("LAST : " + v); } var high = (from q in dc.RawTicks where q.Stamp > dt[0] select q.Price).Max(); var low = (from q in dc.RawTicks where q.Stamp > dt[0] select q.Price).Min(); //Debug.WriteLine("High From Tick " + high); //Debug.WriteLine("Low From Tick " + low); High = Convert.ToDouble(high); Low = Convert.ToDouble(low); } catch (Exception ex) { Debug.WriteLine("get_10min_high_low_from_ticks DATA BASE BUSY : " + ex.Message); High = 0; Low = 0; } }
static public void get_10min_high_low_from_ticks_Prev_TimeFrame(out double High, out double Low) { try { //get 10 min high AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString; var last = (from q in dc.OHLC_10_Minutes orderby q.Stamp descending select new { q.Stamp, q.L, q.H, q.C }).Take(2); List<DateTime> dt = new List<DateTime>(); High = 0; Low = 0; foreach (var v in last) { dt.Add(v.Stamp); //Debug.WriteLine(v.Stamp + " Last " + v.C + " High : " + v.H + " Low : " + v.L); High = Convert.ToDouble(v.H); Low = Convert.ToDouble(v.L); } } catch (Exception ex) { Debug.WriteLine("get_10min_high_low_from_ticks DATA BASE BUSY : " + ex.Message); High = 0; Low = 0; } }
static public void insertTicks(DateTime Stamp, int Price) { AlsiDBDataContext dc = new AlsiDBDataContext(); int p = Price; RawTick c = new RawTick { Stamp = Stamp, Price = p }; dc.RawTicks.InsertOnSubmit(c); dc.SubmitChanges(); }
static public List<Trade> GetTradeLogFromDatabase(int numberofLogs) { List<Trade> logdata = new List<Trade>(); try { AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = AlsiUtils.Data_Objects.GlobalObjects.CustomConnectionString; var count = (from p in dc.TradeLogs select (p.Time)).Count(); var result = (from q in dc.TradeLogs orderby q.Time ascending select new { q.Time, q.BuySell, q.Reason, q.Price, q.Volume, q.ForeColor, q.BackColor }) .Skip(count - numberofLogs) .Take(numberofLogs); foreach (var v in result) { Trade l = new Trade(); l.TimeStamp = (DateTime)v.Time; // l.BuyorSell = v.BuySell; // l.TradeReason = v.Reason; l.TradedPrice = (double)v.Price; l.TradeVolume = (int)v.Volume; l.ForeColor = Color.FromName(v.ForeColor); l.BackColor = Color.FromName(v.BackColor); logdata.Add(l); } return logdata; } catch (Exception ex) { return logdata; } }
private void SetOHLC_IntraTrade_SingleTradePL() { var tpl = new List<ProfitAlgoLayer.TakeProfitTrade>(); StreamWriter sr = new StreamWriter(@"d:\ohlcPL2.csv"); int C = _CompletedTrades.Count; double totProfit = 0; double start = 0; var dc = new AlsiDBDataContext(); var M = dc.OHLC_5_Minutes.ToList(); for (int i = 1; i < C; i++) { var pl5 = from x in _FullTradeList where x.TimeStamp >= _CompletedTrades[i].OpenTrade.TimeStamp && x.TimeStamp <= _CompletedTrades[i].CloseTrade.TimeStamp select x; tpl = pl5.ToList(); if (tpl.Count > 1) { foreach (var v in tpl) { var f = M.Where(z => z.Stamp == v.TimeStamp).First(); var market = new Price(f.Stamp, f.O, f.H, f.L, f.C, f.Instrument); start = tpl.First().TradedPrice; double o = 0; if (tpl[0].Reason == Trade.Trigger.OpenShort) o = (start - market.Open) ; if (tpl[0].Reason == Trade.Trigger.OpenLong) o = (market.Open - start) ; double h = 0; if (tpl[0].Reason == Trade.Trigger.OpenShort) h = (start - market.High) ; if (tpl[0].Reason == Trade.Trigger.OpenLong) h = (market.High - start) ; double l = 0; if (tpl[0].Reason == Trade.Trigger.OpenShort) l = (start - market.Low) ; if (tpl[0].Reason == Trade.Trigger.OpenLong) l = (market.Low - start) ; double c = 0; if (tpl[0].Reason == Trade.Trigger.OpenShort) c = (start - market.Close) ; if (tpl[0].Reason == Trade.Trigger.OpenLong) c = (market.Close - start) ; var P = new Price(); P.TimeStamp = market.TimeStamp; P.Open = o; P.High = h; P.Low = l; P.Close = c; if (v.TimeStamp == tpl.Last().TimeStamp) { totProfit += tpl.Last().RunningProfit; } OHLC_LIST.Add(P); sr.WriteLine(P.TimeStamp.Date +","+P.TimeStamp +","+v.Reason + "," + P.Open + "," + P.High + "," + P.Low + "," + P.Close + "," + 0 + "," + market.Open + "," + market.High + "," + market.Low + "," + market.Close + "," + totProfit ); } //Debug.WriteLine(P.Close); // Debug.WriteLine(i + "," + (o + tpl[0].RunningTotalProfit_New) + "," + (h + tpl[0].RunningTotalProfit_New) + "," + (l + tpl[0].RunningTotalProfit_New) + "," + (c + tpl[0].RunningTotalProfit_New)); // Debug.WriteLine(i + "," + P.Open + "," + "," + P.High + "," + P.Low + "," + P.Close); } } sr.Close(); }
private void ViewDBPrices(int N, DataBase.dataTable Table) { AlsiDBDataContext dc = new AlsiDBDataContext(); if (Table == DataBase.dataTable.MasterMinute) { int count = dc.MasterMinutes.Count(); DBPricesGridView.DataSource = dc.MasterMinutes.Skip(count - N).OrderByDescending(z => z.Stamp); } if (Table == DataBase.dataTable.AllHistory) { int count = dc.AllHistoricMinutes.Count(); DBPricesGridView.DataSource = dc.AllHistoricMinutes.Skip(count - N).OrderByDescending(z => z.Stamp); } }
private void TableMastrMinRadioButton_CheckedChanged(object sender, EventArgs e) { AlsiDBDataContext dc = new AlsiDBDataContext(); int x = dc.MasterMinutes.Count(); VieDBNumericUpDown.Maximum = x; dbPriceCountLabel.Text = "Datapoints : " + x.ToString(); }
public static void UpdatetoMinuteImport() { AlsiDBDataContext dc = new AlsiDBDataContext(); dc.Connection.ConnectionString = GlobalObjects.CustomConnectionString; dc.ClearImportTable(); decimal progress = 0; decimal totProgress = GlobalObjects.Points.Count; foreach (Price price in GlobalObjects.Points) { int open = (int)price.Open; int high = (int)price.High; int low = (int)price.Low; int close = (int)price.Close; int volume = (int)price.Volume; ImportMinute c = new ImportMinute { Stamp = price.TimeStamp, O = open, H = high, L = low, C = close, V = volume, Instrument = price.InstrumentName }; dc.ImportMinutes.InsertOnSubmit(c); dc.SubmitChanges(); progress++; int p = Convert.ToInt16(100 * (progress / totProgress)); } GlobalObjects.Points.Clear(); dc.UpadteImport(); dc.CleanUp(); }