Profile Picture

Get opening price of the bar when an order is placed?

Posted By rekab 6 Years Ago
Message
Posted Wednesday December 14 2011
Hi I'm trying to set my profit target to be a percentage based on the opening price of the bar when the order was placed. Can anyone tell me how to do that in C#?

So far, I've got:

public override void OrderFilled(Position position, Trade trade)
{
   if (trade.TransactionType == TransactionType.Buy || trade.TransactionType == TransactionType.Short )
   {
      position.SetProfitTargetPrice(Bars.Current.Open * (1 + ProfitTarget));
   }
}

But if the order doesn't get filled on the same bar as when the order was placed, that won't work. So what I want is something like:

public override void OrderFilled(Position position, Trade trade)
{
   if (trade.TransactionType == TransactionType.Buy || trade.TransactionType == TransactionType.Short )
   {
      position.SetProfitTargetPrice(Bars.position.EntryTime.Open * (1 + ProfitTarget));
   }
}

Of course, that won't work.

Any help would be greatly appreciated.

Thanks!
Posted Wednesday December 14 2011
The best way is probably to save what the open price is when you place the order. You can do this in the CustomString or Tag property of PositionSettings (and they'll be copied to the corresponding fields on the order). With the CustomString, you'll have to convert it to a string in back. The Tag won't be saved between live different live runs.

Thanks,
Daniel
Posted Wednesday December 14 2011
Thanks Daniel,

The more I think about it though, the more I'm wondering if this might work:

public override void NewBar()
{
   PositionSettings settings = new PositionSettings();
   settings.PositionType = PositionType.Long;
   settings.OrderType = OrderType.Market;
   settings.ProfitTarget = Bars.Current.Open * (1 + ProfitTarget);
   settings.ProfitTargetType = TargetPriceType.AbsolutePrice;


   // (order entry code goes here)
}


If NewBar() runs after each bar, that should give me the opening price of the bar on which the order is placed, right?


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems