protected void PlaceTargetOrder(double qty, double price, string name) { price = new PriceCalculator(LoggingConfig).RoundPrice(price, Instrument); if (TargetOrderType == OrderType.Market) StrategyOrder = MarketOrder(Instrument, EffectiveOrderSide, qty, name); else if (TargetOrderType == OrderType.Limit) StrategyOrder = LimitOrder(Instrument, EffectiveOrderSide, qty, price, name); else if (TargetOrderType == OrderType.MarketOnClose) { StrategyOrder = MarketOrder(Instrument, EffectiveOrderSide, qty, name); StrategyOrder.Type = OrderType.MarketOnClose; } if (string.IsNullOrWhiteSpace(IbBrokerAccountNumber)) { LoggingUtility.WriteError(LoggingConfig, "IB BROKER NUMBER IS NOT SET. NO ORDER SUBMITTED"); return; } StrategyOrder.Account = IbBrokerAccountNumber; if (AutoSubmit) StrategyOrder.Send(); //CurrentStrategyOrdersList.Add(newOrder); }
/// <summary> /// /// </summary> /// <param name="bar"></param> /// <returns></returns> protected double GetTargetPrice(Bar bar) { GapType gap = GapType.Allowed; double targetPrice = bar.Open; PriceCalculatorInput priceInput = new PriceCalculatorInput() { Strategy = this, Atr = EffectiveAtrPrice, CurrentBar = bar, Instrument = Instrument, OrderSide = EffectiveOrderSide }; PriceCalculator calc = new PriceCalculator(LoggingConfig); if (AccountForGaps) { double currentPrice = 0; double lastPrice = 0; gap = GetGapType(bar, ref currentPrice, ref lastPrice); double change = Math.Abs(currentPrice - lastPrice); if (gap != GapType.Allowed) { LoggingUtility.WriteWarn(LoggingConfig, string.Format( "Found a gap of {0:c} ({1:p}) which is {2} from previous price of {3} to new price of {4}", change, change/lastPrice, gap, lastPrice, currentPrice)); } switch (gap) { case GapType.Allowed: break; case GapType.Favorable: UpdateAllowedSlippages(FavorableGapAllowedSlippage, GapType.Favorable); break; case GapType.Unfavorable: UpdateAllowedSlippages(UnfavorableGapAllowedSlippage, GapType.Unfavorable); break; default: throw new InvalidOperationException(""); } targetPrice = calc.CalculateSlippageAdjustedPrice(priceInput); } else { if (PriceCalculationStrategy == Enums.PriceCalculationStrategy.CurrentMarketPrice) targetPrice = bar.Open; else targetPrice = calc.CalculateSlippageAdjustedPrice(priceInput); } LoggingUtility.WriteDebug(LoggingConfig, string.Format("Calculated target price based on {0} strategy: {1:c}", PriceCalculationStrategy, targetPrice)); return targetPrice; }