Ejemplo n.º 1
0
		/// <summary>
		/// Called when a position is modified.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnPositionUpdate(Cbi.PositionUpdateEventArgs e)
		{
			if (!e.Position.Instrument.IsEqual(Instrument) || e.Account.Name != AccountName)
				return;

			Value = (e.Operation == Operation.Remove ? 0 : e.AvgPrice);
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Called when a position is modified.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnPositionUpdate(Cbi.PositionUpdateEventArgs e)
		{
			if (!e.Position.Instrument.IsEqual(Instrument) || e.Account.Name != AccountName)
				return;

			Value = (e.Operation == Operation.Remove ? 0 : (e.Position.MarketPosition == MarketPosition.Long ? 1 : -1) * e.Position.Quantity);
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Called when a position is modified.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnPositionUpdate(Cbi.PositionUpdateEventArgs e)
		{
			if (e.Position.Account.Name == AccountName && e.Position.Instrument.IsEqual(Instrument))
			{
				position = (e.Operation == Operation.Remove ? null : e.Position);
				if (position == null)
				{
					unrealizedPL = 0;
					Value = realizedPL + unrealizedPL;
				}
				else
				{
					double price = 0;
                    if (position.Instrument.MasterInstrument.InstrumentType == InstrumentType.Currency || !Cbi.Position.UseLastPrice4PL)
					{
						if (position.MarketPosition == MarketPosition.Long && position.Account.Connection.MarketDataStreams[e.Instrument].Bid != null)
							price = position.Account.Connection.MarketDataStreams[e.Instrument].Bid.Price;
						else if (position.MarketPosition == MarketPosition.Short && position.Account.Connection.MarketDataStreams[e.Instrument].Ask != null)
							price = position.Account.Connection.MarketDataStreams[e.Instrument].Ask.Price;
						else
							return;

						unrealizedPL = position.GetProfitLoss(price, Strategy.PerformanceUnit.Currency);
					}
					else if (position.Account.Connection.MarketDataStreams[e.Instrument].Last != null)
						unrealizedPL = position.GetProfitLoss(position.Account.Connection.MarketDataStreams[e.Instrument].Last.Price, Strategy.PerformanceUnit.Currency);
					else
						return;

					Value = realizedPL + unrealizedPL;
				}
			}
		}