private void ForwardToday_KLineData(KLineData_RealTime klineData, KLinePeriod period) { ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); //日线,肯定不会跳到下一个bar if (period == KLinePeriod.KLinePeriod_1Day) { dic_KLinePeriod_IsEnd[period] = false; klineData.SetRealTimeData(GetKLineBar(klineData, nextTickBar)); return; } double time = nextTickBar.Time; int nextKLineIndex = FindNextKLineIndex(klineData, time); if (nextKLineIndex == klineData.BarPos) { dic_KLinePeriod_IsEnd[period] = false; klineData.SetRealTimeData(GetKLineBar(klineData, nextTickBar)); } else { dic_KLinePeriod_IsEnd[period] = true; klineData.SetRealTimeData(GetKLineBar(nextTickBar), nextKLineIndex); } }
private bool ForwardToday_MainKLineData() { ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); double nextTickTime = nextTickBar.Time; IKLineData_RealTime klineData = forwardData.GetMainKLineData(); if (dic_KLinePeriod_IsEnd[forwardData.MainKLinePeriod]) { dic_KLinePeriod_IsEnd[forwardData.MainKLinePeriod] = false; } else { int nextKLineIndex = FindNextKLineIndex(klineData, nextTickTime); } //if (nextKLineIndex == klineData.BarPos) //{ // dic_KLinePeriod_IsEnd[period] = false; // klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); //} //else //{ // dic_KLinePeriod_IsEnd[period] = true; // klineData.ChangeCurrentBar(GetKLineBar(nextTickBar), nextKLineIndex); //} return(false); }
private void ForwardToday_TimeLineData(int mainBarPosIfFinished) { if (!dataForForward_Code.UseTimeLineData) { return; } ITickBar tickBar = dataForForward_Code.CurrentTickData; ITimeLineData_RealTime timeLineData = dataForForward_Code.CurrentTimeLineData; //该时段已经结束,跳到下一时段 if (isTimeLineEnd) { if (mainBarPosIfFinished > 0) { timeLineData.ResetCurrentBar(); timeLineData.BarPos = forwardDataIndeier.GetTimeLineBarPosIfFinished(mainBarPosIfFinished); return; } TimeLineBar timeLineBar2 = TimeLineUtils.GetTimeLineBar(tickBar, timeLineData.YesterdayEnd); int barP = forwardDataIndeier.GetTimeLineBarPosIfFinished(mainBarPosIfFinished); timeLineData.ChangeCurrentBar(timeLineBar2, barP); //timeLineData.ChangeCurrentBar(timeLineBar2, timeLineData.BarPos + 1); isTimeLineEnd = false; return; } TimeLineBar timeLineBar = TimeLineUtils.GetTimeLineBar(timeLineData, tickBar, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(timeLineBar); if (mainBarPosIfFinished > 0) { isTimeLineEnd = true; } }
public void Receive(ITickBar tickBar) { if (isFirstReceive) { InitBar(tickBar); isFirstReceive = false; return; } if (PresentBarPos == arr_time.Length - 1) { AddTickToBar(tickBar); return; } double nextTime = arr_time[PresentBarPos + 1]; if (tickBar.Time >= nextTime) { PresentBarPos++; InitBar(tickBar); } else { AddTickToBar(tickBar); } }
private void ForwardToday_KLineData(IKLineData_RealTime klineData, KLinePeriod period) { ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); //日线,肯定不会跳到下一个bar if (period.Equals(KLinePeriod.KLinePeriod_1Day)) { dic_KLinePeriod_IsEnd[period] = false; klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); return; } double nextTickTime = nextTickBar.Time; int nextKLineIndex = FindNextKLineIndex(klineData, nextTickTime); if (nextKLineIndex == klineData.BarPos) { dic_KLinePeriod_IsEnd[period] = false; klineData.ChangeCurrentBar(GetKLineBar(klineData, nextTickBar)); } else { dic_KLinePeriod_IsEnd[period] = true; klineData.ChangeCurrentBar(GetKLineBar(nextTickBar), nextKLineIndex); } }
private static void ForwardNextDay_KLine(DataForForward_Code forwardData, IKLineData_RealTime klineData, KLinePeriod period) { ITickBar tickBar = forwardData.CurrentTickData.GetCurrentBar(); int nextbarPos = klineData.BarPos + 1; klineData.ChangeCurrentBar(KLineUtils.GetKLineBar(tickBar), nextbarPos); }
public static KLineBar GetKLineBar(IKLineBar klineBar, ITickData tickData, int startIndex, int endIndex) { KLineBar bar = new KLineBar(); ITickBar endTickBar = tickData.GetBar(endIndex); bar.Time = endTickBar.Time; bar.Start = klineBar.Start; float high = klineBar.High; float low = klineBar.Low; float money = klineBar.Money; int mount = klineBar.Mount; for (int i = startIndex; i <= endIndex; i++) { ITickBar tickBar = tickData.GetBar(i); if (high < tickBar.Price) { high = tickBar.Price; } if (low > tickBar.Price) { low = tickBar.Price; } money += tickBar.Mount * tickBar.Price; mount += tickBar.Mount; } bar.High = high; bar.Low = low; bar.End = endTickBar.Price; bar.Money = money; bar.Mount = mount; bar.Hold = endTickBar.Hold; return(bar); }
private void ForwardNextDay_KLine(KLineData_RealTime klineData, KLinePeriod period) { if (period.PeriodType >= KLineTimeType.DAY) { double day = currentTickData.TradingDay; int nextKLineIndex = FindNextKLineIndex(klineData, day); if (nextKLineIndex != klineData.BarPos) { dic_KLinePeriod_IsEnd[period] = true; klineData.SetRealTimeData(GetKLineBar(currentTickData), nextKLineIndex); } else { dic_KLinePeriod_IsEnd[period] = false; klineData.SetRealTimeData(GetKLineBar(klineData, currentTickData)); } return; } ITickBar tickBar = currentTickData.GetCurrentBar(); KLineData_DaySplitter daySplitter = dic_Period_DaySplitter[period]; daySplitter.NextDay(); //klineData.BarPos = daySplitter.CurrentDayKLineIndex; ForwardKLine_NextPeriod(klineData, daySplitter.CurrentDayKLineIndex, tickBar); }
public void Receive(ITickBar tickBar) { if (isFirstReceive) { InitBar(tickBar); isFirstReceive = false; return; } if (BarPos == arr_time.Length - 1) { AddTickToBar(tickBar); return; } double nextTime = arr_time[BarPos + 1]; if (tickBar.Time >= nextTime) { BarPos++; InitBar(tickBar); } else { AddTickToBar(tickBar); } int m = 12; if (tickBar.Price != Price) { m++; } }
private void ForwardToday_TimeLineData(ITimeLineData_RealTime timeLineData) { if (timeLineData == null) { return; } ITickData_Extend currentTickData = forwardData.CurrentTickData; ITickBar nextTickBar = currentTickData.GetBar(currentTickData.BarPos + 1); int nextTimeLineBarPos = timeLineData.BarPos + 1; if (nextTimeLineBarPos >= timeLineData.Length) { TimeLineBar timeLineBar = GetTimeLineBar(timeLineData, nextTickBar, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(timeLineBar, timeLineData.BarPos); return; } else { double nextTime = timeLineData.Arr_Time[nextTimeLineBarPos]; TimeLineBar timeLineBar; if (nextTickBar.Time >= nextTime) { timeLineBar = GetTimeLineBar(nextTickBar, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(timeLineBar, nextTimeLineBarPos); } else { timeLineBar = GetTimeLineBar(timeLineData, nextTickBar, timeLineData.YesterdayEnd); timeLineData.ChangeCurrentBar(timeLineBar, timeLineData.BarPos); } } }
public void Receive(ITickBar tickBar) { string code = tickBar.Code; if (!dicTickData.ContainsKey(code)) { TickData_Present newTickData = new TickData_Present(10000); newTickData.Code = code; //List<ITickBar> tickBarList = new List<ITickBar>(); ((TickBar)tickBar).Mount = tickBar.TotalMount; ((TickBar)tickBar).Add = tickBar.Hold; newTickData.Recieve(tickBar); dicTickData.Add(code, newTickData); if (OnTickDataReceived != null) { OnTickDataReceived(this, newTickData, tickBar); } return; } TickData_Present tickData = dicTickData[code]; ITickBar lastTick = tickData; ((TickBar)tickBar).Mount = tickBar.TotalMount - lastTick.TotalMount; ((TickBar)tickBar).Add = tickBar.Hold - lastTick.Hold; tickData.Recieve(tickBar); if (OnTickDataReceived != null) { OnTickDataReceived(this, tickData, tickBar); } }
private void DrawRecentTick(Graphics g, Point startPoint, ITickData tickData, double lastEndPrice) { int defaultLeft = startPoint.X + 2; Point p = new Point(defaultLeft, startPoint.Y + 2); Color titleColor = ColorUtils.GetColor("#808080"); g.DrawString("时间", new Font("宋体", 11, FontStyle.Regular), new SolidBrush(titleColor), p); p.X += 90; g.DrawString("价位", new Font("宋体", 11, FontStyle.Regular), new SolidBrush(titleColor), p); p.X += 40; g.DrawString("现手", new Font("宋体", 11, FontStyle.Regular), new SolidBrush(titleColor), p); p.X += 40; g.DrawString("增仓", new Font("宋体", 11, FontStyle.Regular), new SolidBrush(titleColor), p); p.X += 40; g.DrawString("开平", new Font("宋体", 11, FontStyle.Regular), new SolidBrush(titleColor), p); if (tickData == null) { return; } //TODO 未考虑周全 int showCount = tickData.BarPos >= 15 ? 15 : tickData.BarPos; int startBarPos = tickData.BarPos - showCount; for (int i = 0; i < showCount; i++) { ITickBar tickBar = tickData.GetBar(startBarPos); ITickBar lastTickBar = startBarPos <= 0 ? null : tickData.GetBar(startBarPos - 1); p.X = defaultLeft; p.Y += 25; DrawTickBar(g, p, tickBar, lastTickBar, lastEndPrice); startBarPos++; } }
private void AddTickToBar(ITickBar tickBar) { float price = tickBar.Price; arr_price[BarPos] = price; arr_mount[BarPos] += tickBar.Mount; arr_hold[BarPos] = tickBar.Hold; arr_UpRange[BarPos] = (float)Math.Round(price - YesterdayEnd, 2); arr_UpPercent[BarPos] = (float)Math.Round((price - YesterdayEnd) / price * 100, 2); }
private void onTickDataReceived(object sender, ITickData tickData, ITickBar tickBar) { RealTimeDataReceiver_Code receiver; bool b = dic_Code_Receive.TryGetValue(tickData.Code, out receiver); if (b) { receiver.Receive(tickData, tickBar); } }
private void InitBar(ITickBar tickBar) { arr_start[PresentBarPos] = tickBar.Price; arr_high[PresentBarPos] = tickBar.Price; arr_low[PresentBarPos] = tickBar.Price; arr_end[PresentBarPos] = tickBar.Price; arr_mount[PresentBarPos] = tickBar.Mount; //arr_money[PresentBarPos] = tickBar.mon arr_hold[PresentBarPos] = tickBar.Hold; }
private static void ForwardNextDay_KLine(DataForForward_Code forwardData, IKLineData_RealTime klineData, KLinePeriod period) { ITickBar tickBar = forwardData.CurrentTickData.GetCurrentBar(); int nextbarPos = klineData.BarPos + 1; //TODO 这样nextday算法还是不够准确 while (!klineData.IsDayStart(nextbarPos)) { nextbarPos = klineData.BarPos + 1; } klineData.ChangeCurrentBar(GetKLineBar(tickBar), nextbarPos); }
void InitializeOpenGL() { _glcontrol.MakeCurrent(); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest); _leftTickBar = new VerticalTickBar(); _bottomTickBar = new HorizontalTickBar(); }
public void Receive(ITickData tickData, ITickBar tickBar) { this.tickData = tickData; foreach (KLineData_Present klineData in dicKLineData.Values) { klineData.Receive(tickBar); } timeLineData.Receive(tickBar); if (this.OnRealTimeChanged != null) { this.OnRealTimeChanged(this, new RealTimeChangedArgument(-1, Time, this)); } }
public static TimeLineBar GetTimeLineBar(ITimeLineBar timelineBar, ITickBar tickBar, float lastEndPrice) { TimeLineBar bar = new TimeLineBar(); bar.Code = tickBar.Code; bar.Time = tickBar.Time; bar.Price = tickBar.Price; bar.Hold = tickBar.Hold; bar.Mount = timelineBar.Mount + tickBar.Mount; bar.UpRange = tickBar.Price - lastEndPrice; bar.UpPercent = (float)NumberUtils.percent(tickBar.Price, lastEndPrice); return(bar); }
private CurrentInfo GetCurrentInfo(ITickData tick) { CurrentInfo chartinfo = new CurrentInfo(); chartinfo.code = this.chartComponentController.ChartComponentData.Code; if (tick == null) { return(chartinfo); } //ITickData tick = null; //CurrentInfo chartinfo = new CurrentInfo(); ////ITickData tick = navigate.CurrentTickData; ITickBar tickBar = tick.GetCurrentBar(); //////List<RealDataInfo> reals = currentInfo.GetReal(); //////List<ChartInfo> charts = currentInfo.GetChart(ChartPeriod.DAY, 1); ////ITickBar tickChart = tick.GetBar(navigate.CurrentTickIndex); chartinfo.currentPrice = Math.Round(tick.Price, 2); chartinfo.currentHand = tickBar.Mount; chartinfo.totalHand = tickBar.TotalMount; chartinfo.totalHold = tickBar.Hold; chartinfo.dailyAdd = 0; chartinfo.outMount = 0; chartinfo.outPercent = 0.5; chartinfo.inMount = 0; chartinfo.inPercent = 0.5; //////RealDataInfo r = reals[reals.Count - 1]; //////ChartInfo chart = charts[0]; ITimeLineData realData = chartComponentController.CurrentRealTimeDataReader_Code.GetTimeLineData(); if (realData != null) { ITimeLineBar realChart = realData.GetCurrentBar(); chartinfo.upRange = Math.Round(realChart.UpRange, 2); chartinfo.upPercent = realChart.UpPercent; chartinfo.upSpeed = 0; } //chartinfo.open = realData.StartPrice; //chartinfo.high = chart.HighPrice; //chartinfo.low = chart.LowPrice; ////chartinfo.jsPrice = 0; ////chartinfo.lastJsPrice = Math.Round(r.LastJs, 2); ////double maxUprange = (int)(r.LastJs * 0.04); ////chartinfo.maxUp = r.LastJs + maxUprange; ////chartinfo.maxDown = r.LastJs - maxUprange; ////return chartinfo; //return chartinfo; return(chartinfo); }
private KLineBar GetKLineBar(IKLineBar klineBar, ITickBar tickBar) { KLineBar bar = new KLineBar(); bar.Time = tickBar.Time; bar.Start = klineBar.Start; bar.High = tickBar.Price > klineBar.High ? tickBar.Price : klineBar.High; bar.Low = tickBar.Price < klineBar.Low ? tickBar.Price : klineBar.Low; bar.End = tickBar.Price; bar.Money = klineBar.Money + tickBar.Mount * tickBar.Price; bar.Mount = klineBar.Mount + tickBar.Mount; bar.Hold = tickBar.Hold; return(bar); }
private void XApi_OnRtnDepthMarketData(object sender, ref XAPI.DepthMarketDataNClass marketData) { if (onReturnMarketData == null) { return; } if (!IsInOpenPeriod(marketData.UpdateTime)) { return; } ITickBar tickBar = StructTransfer.TransferTickBar(marketData); onReturnMarketData(sender, ref tickBar); }
private KLineBar GetKLineBar(ITickBar tickBar) { KLineBar bar = new KLineBar(); bar.Time = tickBar.Time; bar.Start = tickBar.Price; bar.High = tickBar.Price; bar.Low = tickBar.Price; bar.End = tickBar.Price; bar.Money = tickBar.Mount * tickBar.Price; bar.Mount = tickBar.Mount; bar.Hold = tickBar.Hold; return(bar); }
private void AddTickToBar(ITickBar tickBar) { if (arr_high[PresentBarPos] < tickBar.Price) { arr_high[PresentBarPos] = tickBar.Price; } if (arr_low[PresentBarPos] > tickBar.Price) { arr_low[PresentBarPos] = tickBar.Price; } arr_end[PresentBarPos] = tickBar.Price; arr_mount[PresentBarPos] += tickBar.Mount; arr_hold[PresentBarPos] = tickBar.Hold; }
private OpenCloseType GetOpenOrClose(ITickBar tickBar, ITickBar lastTickBar) { if (tickBar.Add == 0) { return(OpenCloseType.ChangeHand); } bool isUp = lastTickBar == null ? true : tickBar.Price >= lastTickBar.Price; bool isOpen = tickBar.Add > 0; if (isUp) { return(isOpen ? OpenCloseType.OpenUp : OpenCloseType.CloseDown); } return(isOpen ? OpenCloseType.OpenDown : OpenCloseType.CloseUp); }
private void ForwardCurrentBar() { IKLineData_Extend mainKLineData = this.dataForForward.GetMainKLineData(); ITickBar tickBar = dataForForward.CurrentTickData.GetCurrentBar(); ForwardCurrentBar(mainKLineData, tickBar); foreach (KLinePeriod period in dataForForward.ReferedKLinePeriods) { if (dataForForward.MainKLinePeriod.Equals(period)) { continue; } ForwardCurrentBar(dataForForward.GetKLineData(period), tickBar); } }
private void ForwardKLine(IKLineData_RealTime klineData, bool isBarFinished, bool isBarStart) { ITickBar tickBar = dataForForward_Code.CurrentTickData; if (isBarFinished) { klineData.ResetCurrentBar(); } else if (isBarStart) { KLineBar klineBar = KLineUtils.GetKLineBar(tickBar); klineData.ChangeCurrentBar(klineBar, klineData.BarPos + 1); } else { KLineBar klineBar = KLineUtils.GetKLineBar(klineData, tickBar); klineData.ChangeCurrentBar(klineBar); } dic_KLinePeriod_IsEnd[klineData.Period] = isBarFinished; }
private void DrawTickBar(Graphics g, Point p, ITickBar tickBar, ITickBar lastTickBar, double lastEndPrice) { Color titleColor = ColorUtils.GetColor("#808080"); Color colorNormal = ColorConfig.Color_StockInfo; Color colorRed = ColorConfig.Color_TextUp; Color colorGreen = ColorConfig.Color_TextDown; g.DrawString(GetTimeFormat(tickBar.Time), new Font("宋体", 11, FontStyle.Bold), new SolidBrush(titleColor), p); p.X += 90; g.DrawString(tickBar.Price.ToString(), new Font("宋体", 11, FontStyle.Bold), new SolidBrush(tickBar.Price > lastEndPrice ? colorRed : colorGreen), p); p.X += 40; bool isUp = lastTickBar == null ? true : tickBar.Price >= lastTickBar.Price; g.DrawString(tickBar.Mount.ToString(), new Font("宋体", 11, FontStyle.Bold), new SolidBrush(isUp ? colorRed : colorGreen), p); p.X += 40; g.DrawString(tickBar.Add.ToString(), new Font("宋体", 11, FontStyle.Bold), new SolidBrush(colorNormal), p); p.X += 40; OpenCloseType oct = GetOpenOrClose(tickBar, lastTickBar); g.DrawString(GetOpenCloseTypeName(oct), new Font("宋体", 11, FontStyle.Bold), new SolidBrush(colorNormal), p); }
private void OnReturnMarketData(object sender, ref ITickBar marketData) { string code = marketData.Code; TickData_RealTime tickData; if (dic_TickData.ContainsKey(code)) { tickData = dic_TickData[code]; } else { tickData = new TickData_RealTime(code, currentTradingDay, 200); dic_TickData.Add(code, tickData); } tickData.Recieve(marketData); for (int i = 0; i < Traggers.Count; i++) { Traggers[i].TickDataReceived(this, tickData); } DataReceived?.Invoke(this, tickData); }
public void Recieve(ITickBar tickBar) { this.arr_time.Add(tickBar.Time); this.arr_price.Add(tickBar.Price); this.arr_mount.Add(tickBar.Mount); this.arr_totalMount.Add(tickBar.TotalMount); this.arr_add.Add(tickBar.Add); this.arr_buyPrice.Add(tickBar.BuyPrice); this.arr_buyMount.Add(tickBar.BuyMount); this.arr_sellPrice.Add(tickBar.SellPrice); this.arr_sellMount.Add(tickBar.SellMount); this.arr_isBuy.Add(tickBar.IsBuy); if (this.arr_hold.Count == 0) { this.arr_hold.Add(tickBar.Add); } else { this.arr_hold.Add(this.arr_hold[this.arr_hold.Count - 1] + tickBar.Add); } this.BarPos = this.arr_time.Count - 1; }
void InitializeOpenGL() { _glcontrol.MakeCurrent(); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest); var aliasedLineWidthRange = new float[2]; var antialiasedLineWidthRange = new float[2]; float granularity; GL.GetFloat(GetPName.AliasedLineWidthRange, aliasedLineWidthRange); GL.GetFloat(GetPName.SmoothLineWidthRange, antialiasedLineWidthRange); GL.GetFloat(GetPName.SmoothLineWidthGranularity, out granularity); _leftTickBar = new VerticalTickBar(); _bottomTickBar = new HorizontalTickBar(); }