コード例 #1
0
        /// <summary>Called when new data is received</summary>
        public override void Step()
        {
            base.Step();

            if (Instrument.NewCandle)
            {
                Debugging.LogInstrument();
                Debugging.BreakOnPointOfInterest();
            }

            // Run the position manager
            if (PosMgr != null)
            {
                PosMgr.Step();
            }

            // If there is a pending order, wait for it to trigger or expire
            var pending = PendingOrders.FirstOrDefault();

            if (pending != null)
            {
                // If the price is more than the SL/TP distance from the EP then give up on the order
                var dist = Math.Abs(Instrument.LatestPrice.Mid - pending.TargetPrice);
                if (dist > Math.Abs(pending.TakeProfitRel()) ||
                    dist > Math.Abs(pending.StopLossRel()))
                {
                    Broker.CancelPendingOrder(pending);
                }
                else
                {
                    return;
                }
            }

            // Look for an existing trade for this strategy.
            var position = Positions.FirstOrDefault();

            if (position == null)
            {
                // Look for indicators to say "enter" and which direction.
                QuoteCurrency?ep, tp;
                var           tt = Instrument.FindTradeEntry(out ep, out tp);
                if (tt == null)
                {
                    return;
                }

                // Create a trade in the suggested direction
                var trade = new Trade(Instrument, tt.Value, Label, ep: ep, tp: tp);
                trade.Expiration = (Bot.UtcNow + Instrument.TimeFrame.ToTimeSpan(10)).DateTime;
                if (trade.RtR < 0.2)
                {
                    return;
                }

                // Create a pending order
                Broker.CreatePendingOrder(trade);
                //Broker.CreateOrder(trade);
            }
        }
コード例 #2
0
        /// <summary>Called when new data is received</summary>
        public override void Step()
        {
            base.Step();

            Debugging.BreakOnPointOfInterest();
            if (Instrument.NewCandle)
            {
                Debugging.LogInstrument();
            }

            if (PendingOrders.Any())
            {
                return;
            }

            // Look for an existing trade for this strategy.
            var position = Positions.FirstOrDefault();

            if (position == null)
            {
                // 'ep' must be lower than 'tp'
                var ep   = 0.2;
                var tp   = 0.6;
                var sl   = 0.8;
                var exp  = 1;
                var step = Instrument.MCS;                //MedianCandleSize(-5,1);

                var sym    = Instrument.LatestPrice;
                var trade0 = new Trade(Instrument, TradeType.Buy, Label, ep: sym.Ask + ep * step, sl: sym.Ask - sl * step, tp: sym.Ask + tp * step, risk: 0.5f)
                {
                    Expiration = (Bot.UtcNow + Instrument.TimeFrame.ToTimeSpan(exp)).DateTime
                };
                var trade1 = new Trade(Instrument, TradeType.Sell, Label, ep: sym.Bid - ep * step, sl: sym.Bid + sl * step, tp: sym.Bid - tp * step, risk: 0.5f)
                {
                    Expiration = (Bot.UtcNow + Instrument.TimeFrame.ToTimeSpan(exp)).DateTime
                };

                Broker.CreatePendingOrder(trade0);
                Broker.CreatePendingOrder(trade1);
            }
            else
            {
            }
        }
コード例 #3
0
 /// <summary>Debugging output</summary>
 public override void Dump()
 {
     Debugging.LogInstrument();
 }