Beispiel #1
0
        private bool ExecuteAndModify(TraderCopierArguments arg)
        {
            var historicalTrade = _robot.History.FindLast(arg.Ticket);

            if (historicalTrade != null)
            {
                return(true);
            }

            var symbol           = _robot.MarketData.GetSymbol(arg.SymbolCode);
            var normalizedVolume = symbol.NormalizeVolume(arg.Volume);
            var tradeResult      = _robot.ExecuteMarketOrder(arg.TradeType, symbol, normalizedVolume,
                                                             MT4CopierPrefix + arg.Ticket);

            if (tradeResult.Error == ErrorCode.NoMoney)
            {
                _noMoney = true;
                return(false);
            }
            ExecutedOperationsCount++;
            var success = tradeResult.IsSuccessful;

            if (tradeResult.IsSuccessful)
            {
                success &= UpdatePositionIfNeeded(tradeResult.Position, arg);
            }
            return(success);
        }
Beispiel #2
0
        private bool ValidateFilter(TraderCopierArguments arg)
        {
            var tradeTypeEnabled = (arg.TradeType == TradeType.Buy && _robot.CopyBuy) ||
                                   (arg.TradeType == TradeType.Sell && _robot.CopySell);

            if (!tradeTypeEnabled)
            {
                return(false);
            }

            return(_robot.SymbolsFilter.Length == 0 || _symbolsFilterArray.Contains(arg.SymbolCode.ToLowerInvariant()));
        }
Beispiel #3
0
        private bool UpdatePositionIfNeeded(Position position, TraderCopierArguments arguments)
        {
            if (!_robot.CopyProtectionEnabled)
            {
                return(true);
            }

            var stopLossAbs   = arguments.StopLossAbs;
            var takeProfitAbs = arguments.TakeProfitAbs;

            var sltpChanged = position.TakeProfit != takeProfitAbs || position.StopLoss != stopLossAbs;

            if (sltpChanged)
            {
                ExecutedOperationsCount++;
                return(_robot.ModifyPosition(position, stopLossAbs, takeProfitAbs).IsSuccessful);
            }
            return(true);
        }