It works like this: if account's position is long 1 contract, it reverses the position by placing an order of 2 contracts sell short. And vice versa when MarketPosition = Short.
However , the result wasn't as expected. If I have 1 long position and sell 2 short, it resulted to 1 short. there is no issue. But in next step, when I continue to reverse again, it once again short another 2 contract short instead of buying 2 contracts . (Looks like Position.MarketPosition not updated from Long to short) . Anything I did wrong here ?
Thanks !
{
if (Position.MarketPosition == MarketPosition.Long)
{
{
ChartControl.Dispatcher.InvokeAsync((Action)(() => {
Account a = ChartControl.OwnerChart.ChartTrader.Account;
int quantity0 = Positions[0].Quantity * 2;
Instrument instr = ChartControl.OwnerChart.ChartTrader.Instrument;
Order order0 = a.CreateOrder(instr, OrderAction.Sell,
OrderType.Market, OrderEntry.Automated, TimeInForce.Day, quantity0, 0, 0, "", "Entry1",
Core.Globals.MaxDate, null);
a.Submit(new[] { order0 });
}
));
}
}
if (Position.MarketPosition == MarketPosition.Short)
{
ChartControl.Dispatcher.InvokeAsync((Action)(() => {
Account a = ChartControl.OwnerChart.ChartTrader.Account;
int quantity1 = Positions[1].Quantity * 2;
Instrument instr = ChartControl.OwnerChart.ChartTrader.Instrument;
Order order1= a.CreateOrder(instr, OrderAction.BuyToCover,
OrderType.Market, OrderEntry.Automated, TimeInForce.Day, quantity1, 0, 0, "", "Entry3",
Core.Globals.MaxDate, null);
a.Submit(new[] { order1 });
}
));
}
}

Comment