private void TryToModifyOrder(ExpertDetails openOffer) { var point = PredefinedVariablesWrapper.Point(this); var trendType = openOffer.TrendType; var orderOpenPrice = TradingFunctionsWrapper.OrderOpenPrice(this); var orderStopLoss = TradingFunctionsWrapper.OrderStopLoss(this); var orderTakeProfit = TradingFunctionsWrapper.OrderTakeProfit(this); if (trendType == "ASC") { var bidPrice = PredefinedVariablesWrapper.Bid(this); var takeProfitPriceWith5PointsDifference = bidPrice + (int.Parse(_config.TakeProfit) - 5)*point; if (bidPrice >= takeProfitPriceWith5PointsDifference) { Log.DebugFormat("Time to modify Order. Symbol={0}, TrendType={1}, BidPrice={2}, TakeProfitPriceWith5PointsDifference = {3}", openOffer.Pair, openOffer.TrendType, bidPrice, takeProfitPriceWith5PointsDifference); var updatedStopLoss = orderStopLoss - int.Parse(_config.StopLoss) * point; var updatedTakeProfit = orderTakeProfit + int.Parse(_config.TakeProfit) * point; var modifyOrderResult = OrderOperations.ModifyOffer(this, openOffer.OrderId, orderOpenPrice, updatedStopLoss, updatedTakeProfit); if (!modifyOrderResult) { Log.DebugFormat("ModifyOrder was not executed."); var errorMessage = this.CallMqlMethod("GetLastError", null); Log.DebugFormat("ModifyOrder error = {0}", errorMessage); } if (modifyOrderResult) { LogModifyOrderAttempt(openOffer.OrderId, updatedStopLoss, updatedTakeProfit); } } } if (trendType == "DESC") { var askPrice = PredefinedVariablesWrapper.Ask(this); var takeProfitPriceWith5PointsDifference = askPrice - (int.Parse(_config.TakeProfit) - 5)*point; if (askPrice <= takeProfitPriceWith5PointsDifference) { Log.DebugFormat("Time to modify Order. Symbol={0}, TrendType={1}, AskPrice={2}, takeProfitPriceWith5PointsDifference = {3}", openOffer.Pair, openOffer.TrendType, askPrice, takeProfitPriceWith5PointsDifference); var updatedStopLoss = orderStopLoss + int.Parse(_config.StopLoss)*point; var updatedTakeProfit = orderTakeProfit - int.Parse(_config.TakeProfit)*point; var modifyOrderResult = OrderOperations.ModifyOffer(this, openOffer.OrderId, orderOpenPrice, updatedStopLoss, updatedTakeProfit); if (!modifyOrderResult) { Log.DebugFormat("ModifyOrder was not executed."); var errorMessage = this.CallMqlMethod("GetLastError", null); Log.DebugFormat("ModifyOrder error = {0}", errorMessage); } if (modifyOrderResult) { LogModifyOrderAttempt(openOffer.OrderId, updatedStopLoss, updatedTakeProfit); } } } }
private void AddActiveExpertDetail(TREND_TYPE trendType, double accountBalance, int result, double stopLoss, double takeProfit) { var expertDetailRecord = new ExpertDetails { State = State.Active.ToString(), CreatedOn = DateTime.Now, Pair = _symbol, TimeFrame = GetCurrentTimeFrame(), TrendType = trendType.ToString(), BalanceOnCreate = accountBalance, ExpertName = GetType().Name, OrderId = result, StopLoss = stopLoss, TakeProfit = takeProfit }; ExpertDetailsRepository.Save(expertDetailRecord); Log.DebugFormat("New expertDetail Record was added. Id={0}. Pair={1}, TrendType={2}", expertDetailRecord.Id, expertDetailRecord.Pair, expertDetailRecord.TrendType); }