示例#1
0
        protected void OnData(ITransactionMessage <IPointModel> message)
        {
            var point                = message.Next;
            var account              = point.Account;
            var instrument           = point.Account.Instruments[_asset];
            var points               = instrument.PointGroups;
            var volumes              = _imbalanceIndicator.Calculate(points).Values;
            var performanceIndicator = _performanceIndicator.Calculate(points, Gateways.Select(o => o.Account));

            if (points.Count > 1 && IsNextPoint(point))
            {
                var currentPoint   = points.ElementAt(points.Count - 1);
                var previousPoint  = points.ElementAt(points.Count - 2);
                var currentVolume  = volumes.ElementAt(volumes.Count - 1).Last;
                var previousVolume = volumes.ElementAt(volumes.Count - 2).Last;
                var isLong         = currentVolume > 0 && previousVolume > 0 && previousPoint.Bar.Close > previousPoint.Bar.Open;
                var isShort        = currentVolume < 0 && previousVolume < 0 && previousPoint.Bar.Close < previousPoint.Bar.Open;

                //CreateOrder(point, OrderSideEnum.Buy, 1);

                if (account.ActiveOrders.Count == 0 && account.ActivePositions.Count == 0)
                {
                    if (isLong)
                    {
                        CreateOrder(point, OrderSideEnum.Buy, 1);
                    }
                    if (isShort)
                    {
                        CreateOrder(point, OrderSideEnum.Sell, 1);
                    }
                }

                if (account.ActivePositions.Count > 0)
                {
                    var activePosition = account.ActivePositions.Last();

                    switch (activePosition.Side)
                    {
                    case OrderSideEnum.Buy: if (isShort)
                        {
                            CreateOrder(point, OrderSideEnum.Sell, activePosition.Size.Value + 1);
                        }
                        break;

                    case OrderSideEnum.Sell: if (isLong)
                        {
                            CreateOrder(point, OrderSideEnum.Buy, activePosition.Size.Value + 1);
                        }
                        break;
                    }
                }
            }
        }
示例#2
0
        protected void OnData(ITransactionMessage <IPointModel> message)
        {
            var point                = message.Next;
            var account              = point.Account;
            var gateway              = account.Gateway;
            var instrument           = point.Account.Instruments[_asset];
            var series               = instrument.PointGroups;
            var bidIndicator         = _bidIndicator.Calculate(series);
            var askIndicator         = _askIndicator.Calculate(series);
            var rsiIndicator         = _rsiIndicator.Calculate(series);
            var atrIndicator         = _atrIndicator.Calculate(series);
            var performanceIndicator = _performanceIndicator.Calculate(series, Gateways.Select(o => o.Account));

            if (series.Any())
            {
                var rsiValues   = rsiIndicator.Values;
                var noOrders    = account.ActiveOrders.Any() == false;
                var noPositions = account.ActivePositions.Any() == false;

                if (noOrders && noPositions && rsiValues.Count > 1)
                {
                    var rsiCurrent  = rsiValues.ElementAt(rsiValues.Count - 1).Bar.Close;
                    var rsiPrevious = rsiValues.ElementAt(rsiValues.Count - 2).Bar.Close;

                    if (rsiPrevious < 30 && rsiCurrent > 30)
                    {
                        CreateOrder(point, OrderSideEnum.Buy, 100);
                    }
                    if (rsiPrevious > 70 && rsiCurrent < 70)
                    {
                        CreateOrder(point, OrderSideEnum.Sell, 100);
                    }
                }

                if (noPositions == false)
                {
                    var activePosition = account.ActivePositions.Last();
                    var rsiCurrent     = rsiValues.ElementAt(rsiValues.Count - 1).Bar.Close;
                    var rsiPrevious    = rsiValues.ElementAt(rsiValues.Count - 2).Bar.Close;

                    if (Equals(activePosition.Type, OrderSideEnum.Buy) && rsiPrevious > 70 && rsiCurrent < 70)
                    {
                        CreateOrder(point, OrderSideEnum.Sell, 200);
                    }
                    if (Equals(activePosition.Type, OrderSideEnum.Sell) && rsiPrevious < 30 && rsiCurrent > 30)
                    {
                        CreateOrder(point, OrderSideEnum.Buy, 200);
                    }
                }
            }
        }