Beispiel #1
0
 public void OnPositionOpened(Portfolio portfolio, Position position, bool queued)
 {
     var e = new OnPositionOpened(portfolio, position);
     if (queued)
         this.queue.Enqueue(e);
     else
         OnEvent(e);
 }
Beispiel #2
0
 internal virtual void vmethod_36(Position position)
 {
     if (this.IsInstance)
     {
         this.OnPositionChanged(position);
     }
 }
Beispiel #3
0
 internal virtual void vmethod_35(Position position)
 {
     if (this.IsInstance)
     {
         this.OnPositionClosed(position);
         List<Stop> list = this.idArray_0[position.Instrument.Id];
         if (list != null)
         {
             for (int i = 0; i < list.Count; i++)
             {
                 if (list[i].position == position)
                 {
                     list[i].Cancel();
                 }
             }
         }
     }
 }
Beispiel #4
0
 internal virtual void vmethod_34(Position position)
 {
     if (this.IsInstance)
     {
         this.OnPositionOpened(position);
     }
 }
Beispiel #5
0
        protected override void OnPositionClosed(Position position)
        {
            // When a position is closed, cancel the limit and stop
            // orders that might be associated with this position.
            // But only cancel if the order has not been filled or
            // not been cancelled already.
            if (OCAExitEnabled && !(limitOrder.IsFilled || limitOrder.IsCancelled))
                Cancel(limitOrder);

            // Allow entries once again, since our position is closed.
            entryEnabled = true;
        }
Beispiel #6
0
 private Stop(Strategy strategy, Position position, DateTime time, double level = 0, StopType type = StopType.Trailing, StopMode mode = StopMode.Percent)
 {
     this.strategy = strategy;
     this.position = position;
     this.instrument = position.Instrument;
     this.qty = position.Qty;
     this.side = position.Side;
     this.type = type;
     this.mode = mode;
     this.creationTime = strategy.framework.Clock.DateTime;
     this.completionTime = time;
     this.stopPrice = GetInstrumentPrice();
     if (this.completionTime > this.creationTime)
         strategy.framework.Clock.AddReminder(new Reminder(this.method_9, this.completionTime, null));
 }
Beispiel #7
0
 public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode)
     :this(strategy, position, DateTime.MinValue, level, type, mode)
 {
 }
Beispiel #8
0
 protected virtual void OnPositionChanged(Position position)
 {
 }
Beispiel #9
0
        public override void OnPositionChanged(Position position)
        {
            if (HasLongPosition(1))
                SellStop(position.Qty, position.Price * 0.9975, "StopLoss");

            if (HasShortPosition(1))
                BuyStop(position.Qty, position.Price * (2 - 0.9975), "StopLoss");
        }
Beispiel #10
0
 public override void OnPositionClosed(Position position)
 {
     hold = true;
     canEntry = false;
 }
Beispiel #11
0
 public override void OnPositionOpened(Position position)
 {
     SetStop(position.Price * 0.995, StopType.Trailing);
 }
Beispiel #12
0
        public override void OnPositionChanged(Position position)
        {
            if (HasLongPosition(1))
                SellLimit(position.Qty, position.Price + 1, "TakeProfit");

            if (HasShortPosition(1))
                BuyLimit(position.Qty, position.Price - 1, "TakeProfit");
        }
Beispiel #13
0
 internal void OnPositionClosed(Portfolio portfolio, Position position, bool queued)
 {
     var e = new OnPositionClosed(portfolio, position);
     if (queued)
         this.queue.Enqueue(e);
     else
         OnEvent(e);
 }
Beispiel #14
0
 protected virtual void OnPositionOpened(Position position)
 {
 }
Beispiel #15
0
 public OnPositionOpened(Portfolio portfolio, Position position)
 {
     Portfolio = portfolio;
     Position = position;
 }
Beispiel #16
0
 protected virtual void OnPositionClosed(Position position)
 {
 }
Beispiel #17
0
 public OnPositionChanged(Portfolio portfolio, Position position)
 {
     Portfolio = portfolio;
     Position = position;
 }
Beispiel #18
0
 public override object Read(BinaryReader reader, byte version)
 {
     var p = new Position();
     if (version >= 1)
     {
         p.PortfolioId = reader.ReadInt32();
         p.InstrumentId = reader.ReadInt32();
         p.Amount = reader.ReadDouble();
         p.QtyBought = reader.ReadDouble();
         p.QtySold = reader.ReadDouble();
     }
     return p;
 }
Beispiel #19
0
 internal void OnPositionChanged(Portfolio portfolio, Position position)
 {
     if (Strategy?.Status == StrategyStatus.Running)
         Strategy.EmitPositionChanged(position);
 }
Beispiel #20
0
 public Stop(Strategy strategy, Position position, DateTime time)
     :this(strategy, position, time, 0, StopType.Trailing, StopMode.Percent)
 {
 }
Beispiel #21
0
 public PositionEventArgs(Portfolio portfolio, Position position) : base(portfolio)
 {
     Position = position;
 }
Beispiel #22
0
 protected override void OnPositionOpened(Position position)
 {
     UpdateExitLimit();
 }
Beispiel #23
0
 protected override void OnPositionOpened(Position position)
 {
     // If we want to exit trades using the Stop method, set a
     // a trailing stop indicator when the position is
     // first opened. The stop indicator is not a stop loss
     // order that can be executed by a broker. Instead, the stop
     // just fires the OnStopExecuted event when it it triggered.
     if (StopExitEnabled)
         AddStop(new Stop(this, position, StopLevel, StopType, StopMode));
 }