I am interested in knowing if there is a way to close a trade through a strategy after it was entered manually?
E.g. If I go long on ES manually in "Sim101" and after the trade is on is there a way for me to close that trade through a strategy with ExitLong()?
I tried the following
Entered long manually for ES
Created a strategy that had the following:
private Account myAccount;
in OnStateChange() -> if (State == State.SetDefaults)
lock (Account.All)
myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
In OnBarUpdate()
foreach (Position position in myAccount.Positions)
{
int qty = position.Quantity;
Print("Quantity: " + qty);
Print("Position: " + position.MarketPosition.ToString());
if (position.MarketPosition == MarketPosition.Long)
ExitLong(qty);
}
Enabled the strategy on ES with "Start Behavior" as Immediately submit but that did not exit the trade.
Is there a way to do this? If yes what am I missing in my code snippet?

Comment