So trying to check if strategies are in sync.
I have an indicator that contains the code (after doing all necessary subscriptions etc).
Testing with a single strategy for now.
It works fine for stratQuantity.
For accountQuantity it updates to the correct number when i buy or sell in the sim account for 1 or 2 prints then it goes back to printing the original blance whatever it was before i loaded up the indicator and im not sure why.
this is the code, and my questions follow
private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
{
int stratQuantity = 0;
int accountQuantity = 0;
Print("===");
foreach (StrategyBase strategy in myAccount.Strategies)
{
if(strategy.Account.Name==accountName){
if(strategy.Position.MarketPosition==MarketPosition.Long){
stratQuantity+= strategy.Position.Quantity;
}else if(strategy.Position.MarketPosition==MarketPosition.Short){
stratQuantity-= strategy.Position.Quantity;
}
if(strategy.PositionAccount.MarketPosition==MarketPosition.Long){
accountQuantity = strategy.PositionAccount.Quantity;
}else if(strategy.PositionAccount.MarketPosition==MarketPosition.Short){
accountQuantity = strategy.PositionAccount.Quantity;
}
}
}
Print(strategiesAreSynced);
Print(stratQuantity);
Print(accountQuantity);
if(stratQuantity!=accountQuantity && strategiesAreSynced){
PostData("Strategies not Synced");
strategiesAreSynced = false;
}
if(stratQuantity==accountQuantity){
strategiesAreSynced = true;
}
}
1- is using OnAccountItemUpdate correct for both stratQuantity+= strategy.Position.Quantity and accountQuantity = strategy.PositionAccount.Quantity? Because one is printing correct value and continuously and the latter it briefly then reverts back randomly .
2- Is there a way to access account quantities by instruments rather than from the strategy.PositionAccount.Quantity?
3- general advice for how to this better? I suppose this will work for on one strategy which is useless, but it should be by finding a list of instruments from all active strategies and then adding positions. then finding list of instruments and all their actual PostionAccount quantities before making comparison.

Comment