예제 #1
0
        private void QuotingClick(object sender, RoutedEventArgs e)
        {
            var wnd = new QuotingWindow
            {
                //Security = SecurityPicker.SelectedSecurity,
            };

            if (!wnd.ShowModal(this))
            {
                return;
            }

            var quoting = new MarketQuotingStrategy(wnd.Side, wnd.Volume)
            {
                Security  = wnd.Security,
                Portfolio = wnd.Portfolio,
                Connector = MainWindow.Instance.Connector
            };

            if ((decimal?)TakeProfit.EditValue > 0 || (decimal?)StopLoss.EditValue > 0)
            {
                var tp = (decimal?)TakeProfit.EditValue;
                var sl = (decimal?)StopLoss.EditValue;

                quoting
                .WhenNewMyTrade()
                .Do(trade =>
                {
                    var tpStrategy = tp == null ? null : new TakeProfitStrategy(trade, tp.Value);
                    var slStrategy = sl == null ? null : new StopLossStrategy(trade, sl.Value);

                    if (tpStrategy != null && slStrategy != null)
                    {
                        var strategy = new TakeProfitStopLossStrategy(tpStrategy, slStrategy);
                        AddStrategy($"TPSL {trade.Trade.Price} Vol={trade.Trade.Volume}", strategy);
                    }
                    else if (tpStrategy != null)
                    {
                        AddStrategy($"TP {trade.Trade.Price} Vol={trade.Trade.Volume}", tpStrategy);
                    }
                    else if (slStrategy != null)
                    {
                        AddStrategy($"SL {trade.Trade.Price} Vol={trade.Trade.Volume}", slStrategy);
                    }
                })
                .Apply(quoting);
            }

            AddStrategy($"Quoting {quoting.Security} {wnd.Side} Vol={wnd.Volume}", quoting);
        }
        private void QuotingClick(object sender, RoutedEventArgs e)
        {
            var wnd = new StrategyAddWindow
            {
                //Security = SecurityPicker.SelectedSecurity,
            };

            if (!wnd.ShowModal(this))
            {
                return;
            }

            var security  = wnd.Security;
            var portfolio = wnd.Portfolio;

            var quoting = new MarketQuotingStrategy(wnd.Side, wnd.Volume);

            if (wnd.TakeProfit > 0 || wnd.StopLoss > 0)
            {
                var tp = wnd.TakeProfit;
                var sl = wnd.StopLoss;

                quoting
                .WhenNewMyTrade()
                .Do(trade =>
                {
                    var tpStrategy = tp == 0 ? null : new TakeProfitStrategy(trade, tp);
                    var slStrategy = sl == 0 ? null : new StopLossStrategy(trade, sl);

                    if (tpStrategy != null && slStrategy != null)
                    {
                        var strategy = new TakeProfitStopLossStrategy(tpStrategy, slStrategy);
                        AddStrategy($"TPSL {trade.Trade.Price} Vol={trade.Trade.Volume}", strategy, security, portfolio);
                    }
                    else if (tpStrategy != null)
                    {
                        AddStrategy($"TP {trade.Trade.Price} Vol={trade.Trade.Volume}", tpStrategy, security, portfolio);
                    }
                    else if (slStrategy != null)
                    {
                        AddStrategy($"SL {trade.Trade.Price} Vol={trade.Trade.Volume}", slStrategy, security, portfolio);
                    }
                })
                .Apply(quoting);
            }

            AddStrategy($"Quoting {quoting.Security} {wnd.Side} Vol={wnd.Volume}", quoting, security, portfolio);
        }
예제 #3
0
        private void ProtectMyNewTrades(IEnumerable<MyTrade> trades)
        {
            foreach (MyTrade trade in trades)
            {
                var takeProfit = new TakeProfitStrategy(trade, this.TakeProfitUnit) { UseQuoting = this.UseQuoting, IsTrailing = true, BestPriceOffset = this.BestPriceOffset, PriceOffset = 1 };
                var stopLoss = new StopLossStrategy(trade, this.StopLossUnit) { UseQuoting = this.UseQuoting, IsTrailing = true, BestPriceOffset = this.BestPriceOffset, PriceOffset = 1 };

                var takeProfitStopLoss = new TakeProfitStopLossStrategy(takeProfit, stopLoss);
                ChildStrategies.Add(takeProfitStopLoss);

                //var stopLoss = new StopLossCandleStrategy(this.CandleSeries, trade, this.StopLossUnit);
                //ChildStrategies.Add(stopLoss);

                this.AddInfoLog("Hurrah, we have new trade (#{0}) and I've protected it.", trade.Trade.Id);
            };
        }