Hi there team,
I wrote a base strategy class called StrategyLogger that aims to log the PnL of each trade to a CSV file. My plan is to use this only as a base class, and have my actual strategies that will be running live extend this base class and inherit this CSV writing capability.
The base class overrides OnPositionUpdate() and has some logic in it to begin writing the file header and each line of the file.
A problem I'm running into is this: It seems that this only works with strategies running on a chart. That is, a custom strategy that I create that extends StrategyLogger will ONLY write to the CSV file if it's running on a chart. If I run the same strategy via the Strategies tab, nothing happens.
Why is this?
I've attached 2 files below. One is the basic idea of the StrategyLogger class itself, and another is a simple example strategy that I wrote to illustrate the issue. I run it on a 10 second chart so as to not waste any time and get can get errors, print logs (or no results) quickly.
After doing some debugging with Print statements, it seems the OnPositionUpdate() function is not being called when the strategy is running via the strategies tab, but is being called when the strategy is running on the chart? I had another developer tell me that this is because OnPositionUpdate() is only called within the context of an associated account, and an account is known during chart trading, but no account is known when running via the Strategies tab. This made no sense to me, but still including here to confirm.
Can anyone take a look at the 2 files I've shared below and let me know if the issue is in the code, or there is some other NinjaTrader quirk we are missing?
- Jay

Comment