/// <summary> /// Add Dom snapshot from dde server data /// </summary> /// <param name="table"></param> public static void AddSnapShotFromDde(string symbol, object[][] table) { // Create level 2 shapshot from table Level2 snapShot = new Level2(symbol, table, DateTime.Now); // Get level2 history for symbol Level2History history; if (Level2Histories.ContainsKey(symbol)) { // Add snapshot to existing history = Level2Histories[symbol]; } else { history = new Level2History(symbol) { SaveOnExit = true }; Level2Histories.Add(symbol, history); // Add this history to bars if(QuikQuotesLoader.HistoryBars.ContainsKey(symbol)) QuikQuotesLoader.HistoryBars[symbol].Level2History = history; } if (history.Count != 0 && snapShot.Time.Minute % 5 == 1 && history.Last().Time.Minute != snapShot.Time.Minute) { // Save history history.Save(); } // Add to history history.Add(snapShot); //history.Save(); //history.Load(snapShot.Time); }
/// <summary> /// Main function - robot Entry point /// </summary> protected override void Execute() { base.Execute(); lastSignalTime = DateTime.MinValue; if (Bars.Count > 1) { Level2History.LoadIfNotLoaded(Date[1]); } for (int bar = 1; bar < Bars.Count; bar++) { // Calculate signal SignalType signal = GetSignal(bar); // Close opened if (IsLastPositionActive) { // If isn't closed by stops if (IsLastPositionActive) { CloseStops(bar); // Close long if go below low level if (LastPosition.PositionType == PositionType.Long && signal == SignalType.Sell) { ExitAtMarket(bar + 1, LastPosition, "Sell signal"); ShortAtMarket(bar + 1, "Sell signal"); } // Close short if go upper high level else if (LastPosition.PositionType == PositionType.Short && signal == SignalType.Buy) { ExitAtMarket(bar + 1, LastPosition, "Buy signal"); BuyAtMarket(bar + 1, "Buy signal"); } } } // Open new positions else //if(bar > 1) { // Buy if go up more then deltaUp if (signal == SignalType.Buy) { BuyAtMarket(bar + 1, "Buy signal"); } else if (signal == SignalType.Sell) { ShortAtMarket(bar + 1, "Sell signal"); } } } // Export Equity and Drawdown to Excel //Export export = new Export(this.Bars, this.Positions, this.MarketPosition); //export.OpenExcel(); }
/// <summary> /// Get order with largest volume /// </summary> /// <returns></returns> protected TradeRobotics.DataProviders.Quik.Dom.Order GetFatOrder(DateTime time) { if (Level2History.Count == 0) { return(null); } // Get latest level 2 Level2 level2 = Level2History.LastOrDefault(curLevel2 => curLevel2.Time <= time); if (level2 == null) { return(null); } TradeRobotics.DataProviders.Quik.Dom.Order firstRequest = new TradeRobotics.DataProviders.Quik.Dom.Order(); TradeRobotics.DataProviders.Quik.Dom.Order secondRequest = new TradeRobotics.DataProviders.Quik.Dom.Order(); foreach (TradeRobotics.DataProviders.Quik.Dom.Order request in level2.Orders) { if (request.Volume > firstRequest.Volume) { secondRequest = firstRequest; firstRequest = request; } } //double averageVolume = level2.Orders.Average(curLevel2 => curLevel2.Volume); // If order is fat, return it if (firstRequest.Volume >= secondRequest.Volume * fatOrderCriteria.Value) { return(firstRequest); } return(null); }
/// <summary> /// Constructor /// </summary> /// <param name="symbol"></param> /// <param name="scale"></param> /// <param name="interval"></param> public BarsAndDom(string symbol, BarScale scale, int interval) : base(symbol, scale, interval) { Level2History = new Level2History(Symbol); }