示例#1
0
        public void Scan(TradeBar data)
        {
            _signal.Scan(data);

            Signal = _signal.Signal != _previousSignalType ? _signal.Signal : SignalType.NoSignal;
            _previousSignalType = _signal.Signal;
        }
示例#2
0
        public void EnterTradeSignal(QuoteBar data, bool isWarmingUp)
        {
            EnterSignal.Scan(data);

            if (!isWarmingUp && IsTradable &&
                (EnterSignal.Signal == SignalType.Long || EnterSignal.Signal == SignalType.Short) &&
                _security.Exchange.ExchangeOpen)
            {
                //Creates a new trade profile once it enters a trade
                var profile = new TradeProfile(_symbol, _security.VolatilityModel.Volatility, _risk, data.Price, _maximumTradeSize);

                if (!profile.IsSpreadTradable(data))
                {
                    return;
                }

                profile.ExitSignal = ExitSignal.ExitSignalFactory(profile);

                if (profile.Quantity > 0 && _tradeProfiles.Count == 0)
                {
                    var hmmPrediction = 1m;// _hmmPositionSizing.PredictionRisk();
                    var quantity      = (int)((int)EnterSignal.Signal * profile.Quantity * hmmPrediction);

                    var askLimit   = data.Ask.Close - (1m / 10000m);
                    var bidLimit   = data.Bid.Close + (1m / 10000m);
                    var limitPrice = EnterSignal.Signal == SignalType.Long ? askLimit : bidLimit;

                    try
                    {
                        profile.OpenTicket = _orderMethods.MarketOrder(_symbol, quantity, false, ((int)EnterSignal.Signal).ToString());
                        //profile.OpenTicket = _orderMethods.LimitOrder(_symbol, quantity, OrderUtil.RoundOrderPrices(_security, limitPrice), ((int)EnterSignal.Signal).ToString());
                        var stopPrice = data.Close - (int)EnterSignal.Signal * profile.DeltaStopLoss;
                        profile.StopTicket = _orderMethods.StopMarketOrder(_symbol, -quantity, OrderUtil.RoundOrderPrices(_security, stopPrice));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    //var stopPrice = profile.OpenTicket.AverageFillPrice - (int)EnterSignal.Signal * profile.DeltaStopLoss;

                    /*Console.WriteLine("{0} {1} {2} {3}",
                     *  profile.OpenTicket.OrderEvents.Select((oe) => oe.Direction).First() == OrderDirection.Buy ? "Buy " : "Sell",
                     *  profile.OpenTicket.AverageFillPrice,
                     *  profile.StopTicket.Get(OrderField.StopPrice),
                     *  Math.Abs(data.Ask.Close - data.Bid.Close) * 10000
                     * );*/

                    /*profile.StopTicket = _orderMethods.StopLimitOrder(_symbol, -(int) EnterSignal.Signal * profile.Quantity,
                     *  profile.OpenTicket.AverageFillPrice - (int) EnterSignal.Signal * profile.DeltaStopLoss,
                     *  profile.OpenTicket.AverageFillPrice - (int) EnterSignal.Signal * profile.DeltaStopLoss);*/

                    _tradeProfiles.Add(profile);
                }
            }
        }
示例#3
0
        public void Scan(QuoteBar data)
        {
            _signal.Scan(data);

            if (_signal.Signal != _previousSignalType)
            {
                Signal = _signal.Signal;
            }
            else
            {
                Signal = SignalType.NoSignal;
            }
            _previousSignalType = _signal.Signal;
        }
示例#4
0
        /// <summary>
        /// Executes all the logic when the Enter Signal is triggered
        /// </summary>
        /// <param name="data"></param>
        public void EnterTradeSignal(TradeBar data, Security symbol)
        {
            EnterSignal.Scan(data);
            if (symbol.IsTradable && EnterSignal.Signal == SignalType.Long || EnterSignal.Signal == SignalType.Short)
            {
                //Creates a new trade profile once it enters a trade
                var profile = new TradeProfile(_symbol, _security.VolatilityModel.Volatility, _risk, data.Close, _maximumTradeSize);

                profile.ExitSignal = ExitSignal.ExitSignalFactory(profile);

                var profileQuantity = profile.Quantity;
                if (profileQuantity > 0)
                {
                    profile.OpenTicket = _orderMethods.MarketOrder(_symbol, (int)EnterSignal.Signal * profile.Quantity);
                    profile.StopTicket = _orderMethods.StopMarketOrder(_symbol, -(int)EnterSignal.Signal * profile.Quantity,
                                                                       profile.OpenTicket.AverageFillPrice - (int)EnterSignal.Signal * profile.DeltaStopLoss);

                    _tradeProfiles.Add(profile);
                }
            }
        }