I'll start by saying I know (or at least think) this isn't supported, so I don't know if this will get an answer.
I have been able to get the strategy to check OnStartUp for any open positions in the strategy's account, and identify if any of them are the same instrument the strategy is trading. What I want to do next is assign the Position.Quantity to an IOrder object I use called EntryOrder. The reason for this is because my strategy uses this way:
if(EntryOrder != null && EntryOrder.OrderState == OrderState.Filled)
{
if exit conditions exist
ExitOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, EntryOrder.Quantity, 0, 0, "", "Exit Trigger");
}
So I need some way to bridge the gap between the strategy knowing that there's an open position and being able to fill my EntryOrder object with the .Quantity of the pre-existing position so the strategy can take over management of it.
I'm assuming full risk of what this strategy does, and I want to assert again that this type of coding can be dangerous if not done extremely carefully.
I have this much code so far:
//Check for pre-existing positions on this symbol that this strategy should take over
if(Account.Positions != null)
{
PositionCollection positions = Account.Positions;
foreach (Position pos in positions)
{
if(pos.Instrument.MasterInstrument.Name == Instrument.MasterInstrument.Name && pos.MarketPosition == MarketPosition.Long)
{
[B]//In here I want to assign Position.Quantity to EntryOrder.Quantity [/B]somehow
PositionLabel.Text = Position.MarketPosition.ToString();
}
}
}

Comment