I am using the following code:
bool _closePosition = false;
// if there are active positions they must be part of current trade object
if (PositionAccount.MarketPosition != MarketPosition.Flat)
{
// check to see if current trade object has active trade
_closePosition = CurrentTrade.TradeStatus == tradeStatusState.None;
// close all positions if necessary
if (_closePosition)
{
int _qty = PositionAccount.Quantity;
if (PositionAccount.MarketPosition == MarketPosition.Long)
{
// execute opposite order
EnterShort(_qty); // <--- this is closing the unwanted position
ExitShort(); // <---- i was hoping that this would set the strategy marketposition to flat
}
}
}
When testing I added a Buy Market using the chart trader and the strategy quickly closed the order by placing a Sell Market via the strategy (using code above). The account market position becomes flat (like it should) but the strategy market position is now short.
I tried adding an ExitShort() command thinking that it would reset the strategy so the account and strategy market positions were both in sync.
I can't use the flatten command because it shuts down the strategy. Is there another way to do this without using an unmanaged approach?

Comment