yesterday, after handling with a OCO-problem, I asked myself what are the differences in programming if I want to go live with a strategy.
During backtesting only at the open of a new bar orders are triggered, so I think there is a little difference and maybe you have to change your code for live-trading.
Because I'm not new to programming but to NinjaTrader I wanted to know what are your experiences or best-practices and what are the changes in code to go live with the strategy. Error-Handling is also an interesting point ...
There is a lot to cover on this subject, but some advice I hope you take to heart is this:
Always test your strategy in simulation mode in a live market before allowing cash trades.
I have learned too many times that something did not behave as expected, but only after I started placing live trades. These things did not show up in Market Replay and especially did not show up in backtesting.
Some examples I can think of:
One strategy that focuses on longs, a separate on shorts, each trying to open or close a position. [only if you have two separate strategies on same instrument]
Stop orders - in general.
Limit orders - in general.
Hopefully some others will chime in as well. There is a LOT to cover on this topic
The following user says Thank You to Big Mike for this post:
there are standard NT approaches that are recommended to do using methods onbarupdate, onorderupdate, onorederexecution, onpositionupdate, again we might need to wait for NT7 for better order processing control. That control could depend on data provider.
These problems are really not easy to explain, but basically...
I only use market orders in strategies anymore. This is because limit orders have several problems with backtests.
Everything I say below is assuming BACKTESTING not live trading:
First, if at any time on a bar your limit price is hit, it will be filled. Let's say you have a 5m bar or some other bar which can be large. Say your target is 4 ticks. Price can be at the top of the bar and falling, fill your LONG limit order, and then close on the low without ever going +1 tick after filling you, yet Ninja will show a profitable trade if there was 4 ticks between the bar open and your limit price. Ninja doesn't know the OHLC order, I get that.
Second, you try to set your profit target to not ever fill on bar #1. At least 2 bars are required. This plays it 'safe'. If you call SetProfitTarget after BarsSinceEntry() > 1, it will still show profit target on bar 1, even though it was called on bar 2 and during bar 1 no PT even existed.
Third, if you name your orders the same (ie "long" and "short") and you set your profit targets in #onbarupdate say right after the Enter() command, many times NT has the wrong PT values because it was left-over from a previous signal. If a signal 5 entries ago had a target of 4 ticks, NT screws up and doesn't always recalculate the new PT based on the new entry.
Needless to say, I wrote a lot of code that fixes all of these -- to the best of my knowledge -- but still I just prefer to deal with market orders in strategies given all my negative experience with limit orders.
Not practical when trying to test 1 year of data. Hell, not practical when trying to test more than a couple weeks.
But all of this backtest talk is steering me off course. I am really trying to stay away. I spent over a year on this stuff and have nothing to show for it, with the exception of identifying tons of bugs. I am not getting paid by NT so that is worthless.
My focus is 100% discretionary. Backtesting is just useful to me in the idea of proving an approximate concept is approximately profitable.