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

Multi-instrument Strategy

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

    Multi-instrument Strategy

    Hi,
    I am facing some issues while programming my strategy in NT.
    When I try to add an instrument to my strategy I got the following message in the output:
    **NT** The strategy 'xxxXxxx/bf6de4be4ed142c1b19ceb91e3dd45cc' has called the Add() method with an invalid instrument. Either 'XXXYYY' does not exist in the Instrument Manager or the specified exchange has not been configured.
    N.B.: I am trading forex and got the same error for all the instruments.
    Thank you for your help,
    R.E.

    #2
    Does the instrument exist in your instrument manager? Can you make a chart of it?

    Comment


      #3
      Hello snoppss,

      Thank you for your post.

      Can you provide the full line of code for Add() in your Intialize() method?

      Comment


        #4
        Hi,
        Thank you for your answer,
        So, the code of my add command is lines like:
        Add("EURUSD",PeriodType.Minute, period);
        In normal time, I can draw the chart of the EURUSD, that's why I use now only this currency, but when I tried to make a chart of it now, it refused to show something else than "Loading data...". I don't get the problem, I remove the strategy of the other chart but it got no effect.

        Thank you for your help,
        R.E.

        Comment


          #5
          Hello R.E.,

          Thank you for your response.

          Change the line to Add("$EURUSD",PeriodType.Minute, period);

          Comment


            #6
            Hi,
            Thank you guys, it works perfectly now.
            I have a last query how to add the other instruments I need. Should I enter some paramaters, or there is any tutorial?

            Thank you in advance,
            R.E.

            Comment


              #7
              Hello snoppss,

              Thank you for your response.

              You can find information at the following link: http://ninjatrader.com/support/helpG...nstruments.htm

              Examples can be found under Tools > Edit NinjaScript > Strategy > SampleMultiInstrument and SampleMultiTimeframe.
              Last edited by NinjaTrader_PatrickH; 07-28-2015, 12:15 PM.

              Comment


                #8
                Hi,
                Thank you for your answer, but I still have troubles with the multi-instrument strategy. I don't need in my strategy anything else than the data of the current bar, but I use something like 14 instruments, and I got this weird error:

                Error on calling 'OnBarUpdate' method for indicator 'X': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                the only data I use in my code is:
                ....
                Closes[k][0];
                ....

                I guess that while my strategy work on the historical data it doesn't process simultaneously the data series, and that NT doesn't got all the information needed stored to calculate my formula.
                What can I do with that?

                Thank you in advance,
                R.E.
                Last edited by snoppss; 07-28-2015, 09:06 AM.

                Comment


                  #9
                  Hello snoppss,

                  Thank you for your response.

                  You would need to ensure the data is available before accessing the values. Information on this matter is available at the following link: http://ninjatrader.com/support/forum...ead.php?t=3170

                  Example would be the following:
                  Code:
                  if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
                  return;
                  // ensure both the primary and secondary series have enough data.

                  Comment


                    #10
                    Hi,
                    thank you for your answer,

                    The problem I face doesn't appear when using the historical data but only when I use the real time data. I tought it was because I use my instruments with differents time periods (5min and 1 min) but now I make it all 5 minutes, but I still have problems with the real time data.

                    Furthermore, I have 11 instruments and when I add this code at the beggining of my indicator ( because it doesn't seems to work with a strategy I switched to an indicator):
                    for(int i=0;i<=11;i++)
                    if(CurrentBars[i]<=10){
                    Plot0.Set(0);
                    return;
                    }
                    Now I have no errors, but I got only an horizontal line with y=0.
                    I also add something to use the good bars in progress but no result.
                    What can I do then to fix the problem?

                    Thank you in advance,
                    R.E.

                    Comment


                      #11
                      Are you still getting that "Error on calling 'OnBarUpdate' method for indicator 'X' " error or is it the plot line at 0 that you are more worried about?

                      It looks like you are setting it to 0 for each iteration of the loop. I don't know what else you're doing in the code to give a better answer for you. More context plz?

                      Comment


                        #12
                        Hello snoppss,

                        Thank you for your response.

                        May we review your code on our end? If you prefer you can send it to platformsupport[at]ninjatrader[dot]com with this thread in reference: "http://ninjatrader.com/support/forum/showthread.php?t=76629"

                        Comment


                          #13
                          Thank you guys for your help,
                          I simplified a lot my code, so now I simply add 11 instruments to the chart (I think there is some trouble with that), and in the onBarUpdate method I simply verify that it is the first instrument (BarsInProgress==0) and then there is enough data (however I don't use the past data). At the end I just plot one of the instruments close value. But I still have this 0-line drawed.

                          I sent the code in the mail as specified.
                          N.B.: If we remove some lines the code seems to work but it is an impression because if we want some minutes the chart disappears.

                          Thank you in advance,
                          R.E.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Waxavi, Today, 02:00 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post Waxavi
                          by Waxavi
                           
                          Started by elirion, Today, 01:36 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post elirion
                          by elirion
                           
                          Started by gentlebenthebear, Today, 01:30 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post gentlebenthebear  
                          Started by samish18, Yesterday, 08:31 AM
                          2 responses
                          9 views
                          0 likes
                          Last Post elirion
                          by elirion
                           
                          Started by Mestor, 03-10-2023, 01:50 AM
                          16 responses
                          391 views
                          0 likes
                          Last Post z.franck  
                          Working...
                          X