Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 internal virtual void vmethod_36(Position position)
 {
     if (this.IsInstance)
     {
         this.OnPositionChanged(position);
     }
 }
Ejemplo n.º 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();
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 internal virtual void vmethod_34(Position position)
 {
     if (this.IsInstance)
     {
         this.OnPositionOpened(position);
     }
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 7
0
 public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode)
     :this(strategy, position, DateTime.MinValue, level, type, mode)
 {
 }
Ejemplo n.º 8
0
 protected virtual void OnPositionChanged(Position position)
 {
 }
Ejemplo n.º 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");
        }
Ejemplo n.º 10
0
 public override void OnPositionClosed(Position position)
 {
     hold = true;
     canEntry = false;
 }
Ejemplo n.º 11
0
 public override void OnPositionOpened(Position position)
 {
     SetStop(position.Price * 0.995, StopType.Trailing);
 }
Ejemplo n.º 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");
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 14
0
 protected virtual void OnPositionOpened(Position position)
 {
 }
Ejemplo n.º 15
0
 public OnPositionOpened(Portfolio portfolio, Position position)
 {
     Portfolio = portfolio;
     Position = position;
 }
Ejemplo n.º 16
0
 protected virtual void OnPositionClosed(Position position)
 {
 }
Ejemplo n.º 17
0
 public OnPositionChanged(Portfolio portfolio, Position position)
 {
     Portfolio = portfolio;
     Position = position;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 19
0
 internal void OnPositionChanged(Portfolio portfolio, Position position)
 {
     if (Strategy?.Status == StrategyStatus.Running)
         Strategy.EmitPositionChanged(position);
 }
Ejemplo n.º 20
0
 public Stop(Strategy strategy, Position position, DateTime time)
     :this(strategy, position, time, 0, StopType.Trailing, StopMode.Percent)
 {
 }
Ejemplo n.º 21
0
 public PositionEventArgs(Portfolio portfolio, Position position) : base(portfolio)
 {
     Position = position;
 }
Ejemplo n.º 22
0
 protected override void OnPositionOpened(Position position)
 {
     UpdateExitLimit();
 }
Ejemplo n.º 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));
 }