I wanted to bring to your attention a potential problem I encountered while programming a strategy in Ninjascript and utilizing the 'AtmStrategyClose(string atmStrategyId)' command. I believe this issue could be crucial for those who rely on this command in their trading strategies.
The problem arises when trying to read the profit and loss using the command 'GetAtmStrategyRealizedProfitLoss(string atmStrategyId)' after having first called the 'AtmStrategyClose(string atmStrategyId)' command.
In my testing, I have observed cases where the 'AtmStrategyClose' command successfully closes the strategy, but in many instances, the subsequent call to 'GetAtmStrategyRealizedProfitLoss' returns 0 even though the ATM strategy might have produced a positive/negative result.
I have tried putting a delay (skipping a few OnBarUpdate events) before calling the 'GetAtmStrategyRealizedProfitLoss(...)' after having called the AtmStrategyClose(...) but it did not help.
My workaround was to create a method to close any given ATM strategy and moving the Limit/target orders below/above the current price close depending on the trade direction Long/Short. If i proceed this way then the call to 'GetAtmStrategyRealizedProfitLoss' always returns the correct amount.
Do you think it is due to the particular way the ATM strategy close behavior proceeds ?
*see this link for further details:
Thank you for your attention and valuable input.
Comment