Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best practice for multi-instrument strategy

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

    Best practice for multi-instrument strategy

    I want to develop a strategy that trades 2 instruments.

    1. What's the best way to input the second instrument? as string and then create the instrument in the code? if so, at what state? or is there an option for Instrument type property?

    2. How is it best to handle orders for different instruments? Is it only through Unmanaged approach? The second instrument is traded based on order execution with the first instrument (example: enter long MSFT, when/if filled, enter long AAPL)

    Any code sample would be appreciated.

    Thanks a lot
    Last edited by benharper; 06-28-2016, 12:33 PM.

    #2
    Hello,

    Thank you for the question.

    For the first question, you would need to define a string input as you want to enter text for the input. You can find an example of creating a user defined input here: http://ninjatrader.com/support/forum...73&postcount=2

    For a string input specifically, it would look like the following:

    Code:
    [Display(Name="MyInstrumentInput", Description="", Order=1, GroupName="Parameters")]
    public string MyInstrumentInput
    { get; set; }
    This would make a single text input in the strategies properties. Also you would need to define a default value for the property:

    Code:
    if (State == State.SetDefaults)
    {
    	MyInstrumentInput = "ES 09-16";
    }

    To use this for the instrument to add as the secondary series, you could use the following logic:

    Code:
    else if (State == State.Configure)
    {
    	AddDataSeries(MyInstrumentInput, BarsPeriodType.Tick, 1);
    }

    For handling multiple instruments orders, you can use either the Managed approach or Unmanaged approach, it would depend on what type of logic you want to create.

    There is a simple example that comes with the platform using the managed approach, it is called SampleMultiInstrument.

    Regarding using the opposing instruments orders to control logic, you could look at the following example that demonstrates using Order objects and the OnOrderUpdate/OnExecution overrides to control logic. http://ninjatrader.com/support/forum...ead.php?t=7499


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse, thanks for that reference.

      The question that I'm still trying to resolve and I'm not sure it was answered from the original questions is, when I add that second instrument using the statement

      Add("MSFT", PeriodType.Minute, 1);

      And the base instrument is "FB" using a 1 min time interval.

      In some cases I might want to be long FB, at other times MSFT.

      if (condition1) {
      EnterLong(0, 100, "LE"); // enter long for FB
      } else {
      EnterLong(1, 100, "LE"); // enter long for MSFT
      }
      When I look that the Strategy Analyzer, I can see the FB order/trade, but I never see the MSFT trade.

      The question I have is it possible to trade two different instruments in one strategy or are the other instrument bars only used for conditions to trade the primary instrument?

      Thanks

      Comment


        #4
        Hello,

        thank you for the reply.

        it is possible to trade multiple instrument and also a sample is included with the platform to show this called SampleMultiInstrument.

        What was provided previously and what you have provided now should be fine for trading two instruments.

        You would need to determine if the logic you are using for the entries will overlap to determine if you need to use Multiple entries per direction.If the first instrument has entered, the second could not unless the EntriesPerDirection were set to 2 if you were still in a position.

        Also if the condition is always true, I would not expect the second instrument to get any orders so you would need to verify that is not the case.

        I am able to see what I had provided previously and also the sample that comes with the platform working in a backtest for multiple instruments. In a backtest, because there is only a single chart you could only see the executions for the primary instrument. In the executions and orders tabs you can review the individual instruments trades.

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse, that was very helpful.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          601 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          19 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Started by agclub, 04-21-2024, 08:57 PM
          3 responses
          17 views
          0 likes
          Last Post TradingLoss  
          Working...
          X