Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Multiple Instruments

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

    Multiple Instruments

    Hi

    I am trying to test a strategy in the following manner:

    I have been given a bunch of signals consisting of date and time, instrument, and buy/sell, which I need to test for win ratio and net profit (I will be optimizing the stop loss and take profit levels). For example:

    - EUR/USD, 2013-11-21 16:45, BUY
    - GBP/NZD, 2013-11-22 11:19, BUY
    - EUR/CAD, 2013-11-22 15:01, SELL
    - EUR/JPY, 2013-11-23 02:31, BUY
    - EUR/USD, 2013-11-23 09:57, SELL

    I can get one instrument to test successfully, but how do I add simultaneous testing against other instruments that are not the main instrument that the strategy is running against?

    Thanks

    #2
    Hello Ravish,

    If you would like to test multiple instruments in a single strategy then you will have to use the MultiInstrument approach in NinjaTrader so that you can add the instruments that you would like to test and then be able to filter it out using the BarsInProgress in the order that you add them in. For Example:

    Code:
    protected override void Initialize()
    {
        // Add the $GBPNZD with a 1 Minute timeframe Bars object - BarsInProgress index = 1 
        Add("$GBPNZD", PeriodType.Minute, 1);
     
        // Add the $EURCAD with a 1 Minute timeframe Bars object - BarsInProgress index = 2 
        Add("$EURCAD", PeriodType.Minute, 1);
    } 
    
    protected override void OnBarUpdate()
    {
         //Some entry condition
         if(Close[0] > Open[0])
         {
                EnterLong(1, 10000, "EnterLong for $GBPNZD");
                EnterLong(2, 10000, "EnterLong for $EURCAD");
          }
    }
    Here is a good link to our Help Guide that goes over this in more detail that you may view.


    We also have a sample strategy that come with NinjaTrader that you may use as a reference by going to the Tools -> Edit NinjaScript -> Strategies window and view the "SampleMultiInstrument".
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC

      I have implemented the code as you described, but the OnBarUpdate event is not called during the backtest (I placed a breakpoint in it using Visual Studio).

      What could cause this?

      Thanks

      Comment


        #4
        Hello Ravish,

        This is usually due to not having any Historical Data for the dates that you are requesting or you are running into an error. Can you verify that you have Historical Data for the Forex Pairs that you are wanting to test out by going to the Tools -> Historical Data Manager -> Edit tab?

        Here you should see the instrument name with a "+" Plus mark next to it where you can see what type of data that you have for that instrument for example I may see the "$EURUSD" instrument and that I have "Last" type data, under that "Last" I may see "Minute" meaning that I have "Minute" data, then it will show me what months I have like "December 2013" where I can see the different days that I have data.

        You may view our Help Guide at the following link for some images of what this may look like.
        JCNinjaTrader Customer Service

        Comment


          #5
          Hi JC

          I can confirm that I have data for both pairs that I am working against ($GBPNZD and $AUDNZD), both are Bid prices and are Ticks and are for the past month (which is the timeframe I'm running the backtest in)

          I am running the backtest against the $GBPNZD pair directly, and simply commenting out this line in the Initialize() function, makes the OnBarUpdate event get called again:
          Code:
          Add("$AUDNZD", PeriodType.Tick, 10);
          Leaving that line uncommented however makes the OnBarUpdate event not get called at all.

          Comment


            #6
            Hello Ravish,

            Do you see an error in the Log tab of your Control Center window?
            JCNinjaTrader Customer Service

            Comment


              #7
              Hi JC

              No, there are no errors in the Log tab or in the Output Window.

              Comment


                #8
                Hello Ravish,

                Can you send a toy* NinjaScript code replicating the behavior so that I may look into this? You can Export it as a Source File using the step from our Help Guide at the link below.



                You may either attach the file to this thread or you may send it to me via mail to "support [at] ninjatrader [dot] com" with reference to this thread and put ATTN: JC in the subject line..

                *Toy - basically a stripped down version of code that isn't necessarily the whole logic; making it easier to identify lines of code.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Hi JC

                  Please find attached the toy script.

                  Regards
                  Attached Files

                  Comment


                    #10
                    Hi Ravish,

                    I can backtest your strategy with results, and I also see OnBarUpdate being called without making any changes.

                    The period I tested on was the $GBPUPD as primary on a 1 Minute Data series, from 11/1/2013 to 12/8/2013 with data from Kinetick.

                    As JC mentioned, the primary reason that OnBarUpdate will not be called is that one of the bars array (either primary or an added) do not have the data for required for processing.

                    For us to better understand, can you please tell us who you're connected to?

                    Does the strategy backtest if you switch from Tick to Minute data for your Add() call?

                    What is the exact period you're testing on?
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Hi Matthew

                      I've got the strategy to execute, I had change this:

                      Code:
                      Add("$AUDNZD", PeriodType.Tick, 10);
                      to this:

                      Code:
                      Add("$AUDNZD", PeriodType.Tick, 10, MarketDataType.Bid);
                      Thanks

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by RDTrader16, Today, 10:19 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post RDTrader16  
                      Started by gemify, 03-08-2023, 08:02 AM
                      9 responses
                      148 views
                      0 likes
                      Last Post culpepper  
                      Started by elirion, Today, 10:03 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post elirion
                      by elirion
                       
                      Started by RaddiFX, Today, 09:55 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post RaddiFX
                      by RaddiFX
                       
                      Started by Trader146, 03-29-2024, 01:22 PM
                      4 responses
                      27 views
                      0 likes
                      Last Post Trader146  
                      Working...
                      X