While they are separate strategies as they are now, if I run them on one account they sometimes will trade in opposite directions temporarily creating a flat position in the account. I want to research the effect of running them this way. The motivation for combining them into a single strategy is so that I can backtest this kind of order submission on an account.
Also they will of course sometimes trade in the same direction. This is not a problem in a combined strategy as I can govern allocation in one direction using the global strategy setting EntriesPerDirecton and EntryHandling.AllEntries. But as mentioned it’s when they trade in opposite directions that I need help with.
As a side bar and so you’ll understand my example better, I’d like to keep the strategy logic from the independent strategies separate. I have a couple of object oriented ways I’m doing this: inheritance or composition. Either way, I’m not having any issue constructing a multi-strategy strategy using C#. At runtime NinjaTrader sees my strategy as a single NinjaTrader strategy.
Now, finally to the question. The problem I’m having is with the Ninja order management.
I’m using managed order management.
For example let’s call each sub-strategy in the NinjaScript.Strategies.Strategy.MyMasterStrategy as:
StratA and StratB. These are logical sub objects of my master NinjaScript strategy.
StartA and StratB are called in turn from my MyMasterStrategy.OnBarUpdate. Effectively they are just subroutines of one strategy, but they have their own rules, entry and exit names.
Assume the following order or calls ( sorry I could not format as a table ):
Action Strategy Position Account Position Desired Position
StratA.EnterLong Long 1 Long 1 Long 1
StratB.EnterShort Short1 Short1 Flat
StratA.ExitLong Short1 (error likely) Short1 Short 1
StrabB.ExitShort Flat Flat Flat
The 2nd row shows an account position of Short1 but I really want my account to be Flat. This is the problem because the managed API will sell 2 contracts on the call to EnterShort(1) in order to create the short position because the strategy is long 1. I really just just want it to sell 1 contract.
I know that I can somehow achieve what I want using the Unmanaged API but I’m finding using it to be creating a lot of problems. I’d like to know if there’s an easier way. Something in between the Managed and Unmanaged API.
Comment