public static Order.Types.OrderType ParseOrderType(PendingOrderType orderType) { switch (orderType) { case PendingOrderType.Limit: return(Order.Types.OrderType.Limit); case PendingOrderType.Stop: return(Order.Types.OrderType.Stop); default: return(new Order.Types.OrderType()); //Return something } }
TriState _SendPending(double magicIndex, bool noOrders, string symbolCode, PendingOrderType poType, TradeType tradeType, double lots, int priceAction, double priceValue, double?stopLoss, double?takeProfit, DateTime?expiration, string comment) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); if (noOrders && PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol) != null) { return(new TriState()); } if (stopLoss < 1) { stopLoss = null; } if (takeProfit < 1) { takeProfit = null; } if (symbol.Digits == 5 || symbol.Digits == 3) { if (stopLoss != null) { stopLoss /= 10; } if (takeProfit != null) { takeProfit /= 10; } } int volume = (int)(lots * 100000); double targetPrice; switch (priceAction) { case 0: targetPrice = priceValue; break; case 1: targetPrice = symbol.Bid - priceValue * symbol.TickSize; break; case 2: targetPrice = symbol.Bid + priceValue * symbol.TickSize; break; case 3: targetPrice = symbol.Ask - priceValue * symbol.TickSize; break; case 4: targetPrice = symbol.Ask + priceValue * symbol.TickSize; break; default: targetPrice = priceValue; break; } if (expiration.HasValue && (expiration.Value.Ticks == 0 || expiration.Value == DateTime.Parse("1970.01.01 00:00:00"))) { expiration = null; } if (poType == PendingOrderType.Limit) { if (!PlaceLimitOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); } else if (poType == PendingOrderType.Stop) { if (!PlaceStopOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful) { Thread.Sleep(400); return(false); } return(true); } return(new TriState()); }
TriState _SendPending(double magicIndex, bool noOrders, string symbolCode, PendingOrderType poType, TradeType tradeType, double lots, int priceAction, double priceValue, double? stopLoss, double? takeProfit, DateTime? expiration, string comment) { Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode); if (noOrders && PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol) != null) return new TriState(); if (stopLoss < 1) stopLoss = null; if (takeProfit < 1) takeProfit = null; if (symbol.Digits == 5 || symbol.Digits == 3) { if (stopLoss != null) stopLoss /= 10; if (takeProfit != null) takeProfit /= 10; } int volume = (int)(lots * 100000); double targetPrice; switch (priceAction) { case 0: targetPrice = priceValue; break; case 1: targetPrice = symbol.Bid - priceValue * symbol.TickSize; break; case 2: targetPrice = symbol.Bid + priceValue * symbol.TickSize; break; case 3: targetPrice = symbol.Ask - priceValue * symbol.TickSize; break; case 4: targetPrice = symbol.Ask + priceValue * symbol.TickSize; break; default: targetPrice = priceValue; break; } if (expiration.HasValue && (expiration.Value.Ticks == 0 || expiration.Value == DateTime.Parse("1970.01.01 00:00:00"))) expiration = null; if (poType == PendingOrderType.Limit) { if (!PlaceLimitOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful) { Thread.Sleep(400); return false; } return true; } else if (poType == PendingOrderType.Stop) { if (!PlaceStopOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful) { Thread.Sleep(400); return false; } return true; } return new TriState(); }
private RequestStatus InstallOrder(string symbol, decimal price, decimal? takeProfit, PendingOrderType orderType, int dealSide, int volume) { var dealVolumeDepo = CalculateVolume(ticker); if (dealVolumeDepo == 0) return RequestStatus.MarginOrLeverageExceeded; decimal? stop = StopLossPoints == 0 ? (decimal?)null : price - dealSide * DalSpot.Instance.GetAbsValue(symbol, (decimal)StopLossPoints); decimal? take = TakeProfitPoints == 0 ? takeProfit : price + dealSide * DalSpot.Instance.GetAbsValue(symbol, (decimal)TakeProfitPoints); var order = new PendingOrder { Magic = Magic, Symbol = symbol, Volume = volume, Side = dealSide, PriceSide = orderType, PriceFrom = (float)price, StopLoss = (float?)stop, TakeProfit = (float?)take, ExpertComment = "SlideChannelRobot" }; return robotContext.SendNewPendingOrderRequest( protectedContext.MakeProtectedContext(), RequestUniqueId.Next(), order); }
private bool RemoveAllOrders(List<PendingOrder> orders, PendingOrderType? orderType) { var isOk = true; for (var i = 0; i < orders.Count; i++) { if (orderType != null && orderType != orders[i].PriceSide) continue; var res = robotContext.SendDeletePendingOrderRequest(protectedContext.MakeProtectedContext(), orders[i], PendingOrderStatus.Отменен, null, string.Empty); if (res == RequestStatus.OK) continue; isOk = false; SaveLog(string.Format("Ошибка удаления ордера №{0}", orders[i].ID)); } return isOk; }