internal void addTick(Tick tick) { // long minute = tick.UpdateTime.Hour * 100 + tick.UpdateTime.Minute; if (!mMinute.Equals(minute)) { OnBarData?.Invoke(mBar); mBar = null; } // if (mBar == null) { mBar = new Min1Bar(); mBar.InstrumentID = mInstrumentID; mBar.OpenTime = tick.UpdateTime; mBar.OpenPrice = tick.LastPrice; mBar.HighPrice = tick.LastPrice; mBar.LowPrice = tick.LastPrice; mBar.ClosePrice = tick.LastPrice; } else { mBar.HighPrice = mBar.HighPrice < tick.LastPrice ? tick.LastPrice:mBar.HighPrice; mBar.LowPrice = mBar.LowPrice > tick.LastPrice ? tick.LastPrice : mBar.LowPrice; mBar.ClosePrice = tick.LastPrice; } mBar.Volume = tick.Volume; mBar.OpenInterest = tick.OpenInterest; mBar.Ticks.Add(tick); }
internal void addTick(Tick tick) { if (!tick.InstrumentId.Equals(mInstrumentID)) { return; } //判断是否需要生成新bar if (mBar != null) { DateTime barTime = mTickList[0].UpdateTime; DateTime tickTime = tick.UpdateTime; int barQuotient = (barTime.Day * 1440 + barTime.Hour * 60 + barTime.Minute) / ((int)mSizeType); int tickQuotient = (tickTime.Day * 1440 + tickTime.Hour * 60 + barTime.Minute) / ((int)mSizeType); if (!barQuotient.Equals(tickQuotient)) { OnBarData?.Invoke(mBar, mTickList); mBar = null; mTickList = null; } } //更新bar数据 if (mBar == null) { mBar = new Bar(); mTickList = new List <Tick>(); mBar.InstrumentId = mInstrumentID; mBar.OpenPrice = tick.LastPrice; mBar.HighPrice = tick.LastPrice; mBar.LowPrice = tick.LastPrice; mBar.ClosePrice = tick.LastPrice; mBar.Volume = tick.Volume; mBar.OpenInterest = tick.OpenInterest; mBar.BeginTime = tick.UpdateTime; mBar.SizeType = mSizeType; } else { mBar.HighPrice = mBar.HighPrice < tick.LastPrice ? tick.LastPrice : mBar.HighPrice; mBar.LowPrice = mBar.LowPrice > tick.LastPrice ? tick.LastPrice : mBar.LowPrice; mBar.ClosePrice = tick.LastPrice; } mBar.Volume = tick.Volume; mBar.OpenInterest = tick.OpenInterest; mTickList.Add(tick); }
/// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { CalculateOnBarClose = true; //zigzag zigZagHighSeries = new DataSeries(this, MaximumBarsLookBack.Infinite); zigZagHighZigZags = new DataSeries(this, MaximumBarsLookBack.Infinite); zigZagLowSeries = new DataSeries(this, MaximumBarsLookBack.Infinite); zigZagLowZigZags = new DataSeries(this, MaximumBarsLookBack.Infinite); Add(PeriodType.Tick, 1); Add(PeriodType.Day, 1); historyData = new HistoryData(SaveZigZagDaysOnHistory); dailyData = new DailyData(Time[0]); zigZagDiapasone = new ZigZagDiapasone(5); onBarData = new OnBarData(0); priceVolume = new PriceVolume(); }
protected override void OnBarUpdate() { if (BarsInProgress == 0) { Print("=============="); smaLine = SMA(SMAPeriod)[0]; Print("Day middleValot " + middleValot); Print("SMA Line -> " + smaLine); double procentOfMiddleValot = (middleValot / 100) * ProcentFromMiddleValot; lowLineRSIAnalog = smaLine - procentOfMiddleValot; highLineRSIAnalog = smaLine + procentOfMiddleValot; Print("lowLineRSIAnalog " + lowLineRSIAnalog); Print("highLineRSIAnalog " + highLineRSIAnalog); Print(Time[0].ToString()); OnBarUpdateMain(); Print(Time[0].ToString()); //onBarData.PriceVolumeList.AddPriceVolume(priceVolume); Print("Count PriceVolume: " + onBarData.PriceVolumeOnBar.VolumePriceOnBar.Count); foreach (KeyValuePair <double, double> a in onBarData.PriceVolumeOnBar.VolumePriceOnBar) { string priceVolumeText = string.Format("Price: {0}, count: {1}", a.Key, a.Value); Print(priceVolumeText); } dailyData.OnBarDataList.Add(onBarData); priceVolume = new PriceVolume(); onBarData = new OnBarData(CurrentBar); } if (BarsInProgress == 1) { double openPrice = Opens[1][0]; _lastPrice = Price; Price = openPrice; StopLossAndTakeProfit(Price); double volume = Volumes[1][0]; onBarData.PriceVolumeOnBar.AddPriceVolume(Price, volume); double currentVolume = onBarData.PriceVolumeOnBar.VolumePriceOnBar[Price]; bool isCanInputOrders = false; foreach (DailyData dailyData in historyData.DailyDataList) { foreach (ZigZagDiapasone zigZag in dailyData.ZigZagDiapasoneList) { double averageVolume = dailyData.GetAveragePriceVolume(5); Print("Price -> " + Price); Print("zigZag.SellLevelWithPostTicks -> " + zigZag.SellLevelWithPostTicks); Print("zigZag.BuyLevelWithPostTicks -> " + zigZag.BuyLevelWithPostTicks); if (Price > zigZag.SellLevelWithPostTicks && Price < zigZag.HighZigZag) { if (currentVolume > averageVolume) { BuyOrSell(Price, _lastPrice, OrderAction.Sell); Print("Test sell"); } } else if (Price < zigZag.BuyLevelWithPostTicks && Price > zigZag.LowZigZag) { if (currentVolume > averageVolume) { BuyOrSell(Price, _lastPrice, OrderAction.Buy); Print("Test buy"); } } } } //historyData.ZigZagDiapasoneList[1]. } if (BarsInProgress == 2) { historyData.AddDaylyZigZag(dailyData); int count = dailyData.ZigZagDiapasoneList.Count; for (int i = 0; i < count; i++) { Print("Level by Day -> Index: " + i + " Sell Level: " + dailyData.ZigZagDiapasoneList[i].SellLevel + " Buy Level: " + dailyData.ZigZagDiapasoneList[i].BuyLevel); } dailyData = new DailyData(Time[0]); middleValot = 0; for (int i = 0; i < DayOfSMAValot; i++) { middleValot = middleValot + Highs[2][i] - Lows[2][i]; } middleValot = middleValot / DayOfSMAValot; Print("Day middleValot " + middleValot); } }