Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Handling in composite strategies

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Order Handling in composite strategies

    I have several independent strategies that I want to combine starting with just 2 of them.

    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.
    Last edited by Brillo; 10-20-2015, 12:16 PM.

    #2
    Hello Brillo,

    Thank you for writing in. You could try adjusting your logic to account for the fact that you may be entering in the opposite direction of your current position.

    To enter long for example:
    Code:
    if(Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort(1);
    } else {
    EnterLong(1);
    }
    To exit short for example:
    Code:
    if(Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort(1);
    } else { //Don't do anything so we don't get an error }
    Depending on how your strategies are set up you may use different logic. Alternatively, you could store all of your active orders in a List<IOrder> or an IOrder[] and then write a new method which returned true or false depending on whether it is safe to submit the order and then add that method to all of your entry/exit conditions.

    Please let me know if you have any questions or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Hi Mike,
      Such logic could work. A dependency for the implementation is keeping state as to what position each sub-strategy wants to be in. That's kind of re-inventing the wheel a little too much and leads to overly complicated logic.

      The problem we face could be avoided if we had an option in the Managed API to prevent the managed API from sending the "Close Position" order. All of the issues are caused by that alone.

      For example, if Long and EnterShort is called, there are 2 separate orders generated:
      A Sell called Close position
      A SellShort to create the short position.
      Having the option to avoid sending the 1st order, the "close order" would create the desired effect of being flat.

      Further, While having the automatic close position order feature is helpful, it would not be so difficult if it didn't exist at all. It's very simple for a strategy to detect if it needs to reverse and send the 2 orders itself.

      But I'm not suggesting eliminating the feature, just enable an option for us to suspend it at the strategy instance level.

      A second suggestion is to provide us with the source code for the Managed API along with a risk disclosure and NO SUPPORT. This would also help us really understand how to use the Unmanaged API.

      By the way I didn't mention that I'm most interested in all of this in NT8. I have not seen any new order management features in NT8 that would help with this. Can you suggest the 1st feature, suspension of the close order along with the explanation of it's usefulness in combining multiple strategies?

      Another feature that would help is if I could run multiple strategies in the Strategy analyzer together on one account. That would mitigate the need to combine the strategies into one.

      I expect I can achieve this goal using Replay but I haven't been able to get that to work well. That's another open issue.

      Comment


        #4
        Hello Brillo,

        I have submitted two feature requests on your behalf:

        First, for the ability to turn off the feature that closes your position when reversing positions using an entry order. For example if you turned this feature off, if you are long one position, and you enter short 1, you will end up flat, instead of 1 short.

        Second, a feature request for access to the unsupported source code driving the managed API along with a risk disclaimer.

        I will update this post when I have further information.
        Thank you for your continued patience in the meantime.
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          Thanks Mike.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by trilliantrader, Today, 08:16 AM
          0 responses
          3 views
          0 likes
          Last Post trilliantrader  
          Started by AttiM, 02-14-2024, 05:20 PM
          9 responses
          174 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by funk10101, Today, 08:14 AM
          0 responses
          2 views
          0 likes
          Last Post funk10101  
          Started by adeelshahzad, Today, 03:54 AM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by RookieTrader, Today, 07:41 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X