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 markets

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

    Multiple markets

    Hello,

    I am looking at multiple markets and for each want to read out the open and close times and set up bars which, as each market opens and closes, give me the OHLC for that market. I have a list of the NT market symbols but struggle on the following:
    - how do I access the session manager to get data from multiple markets?
    - I assume I then use "Add" to set up bars for each?
    - do I listen for the bars in OnBarClose or in CurrentDayOHL?

    I am experienced in programming but new to NT and have looked at length and in vain so maybe someone could point me in the right direction?

    Thanks,
    Don

    #2
    Welcome to our forums Don - for working with multiple series I would suggest reviewing this helpguide section here explaining the framework which you would operate in our NinjaScript - http://www.ninjatrader.com/support/h...nstruments.htm

    Then we have a dedicated example to get you going programming via the preinstalled 'SampleMultiInstrument' strategy in NinjaTrader.

    The Session times could be accessed with - http://www.ninjatrader.com/support/h...xtbeginend.htm
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,
      great answer, thanks a lot, I learned quite a bit.
      However - I am still unsure on how to set up the markets. I have the NT symbols for the markets I am looking for - e.g. FDAX, FESX, FGBM, 6A (AUD), 6J (JPY), HE(Lean Hogs). So for these I want to get, after the respective market closes, the OHLC.
      The examples work on individual stocks but how can I set up bars objects for these markets?
      Support appreciated!
      Don

      Comment


        #4
        Hello,

        For futures you would need to specify the expiry from the add method:

        Code:
        			Add("FDAX 12-12", PeriodType.Minute, 1);
        			Add("FESX 12-12", PeriodType.Minute, 1);
        	         	Add("6A 12-12", PeriodType.Minute, 1);
                                etc,
        MatthewNinjaTrader Product Management

        Comment


          #5
          Hi,
          thanks that got me a lot of steps forward. However, there still remain some hurdles.
          - What is the best way of running a backtest on the strategy? I have tried it from the chart of one of the instruments I am loading, and from strategy analyzer.
          - Initialize() is called (twice when running from Analyzer, not sure why) but OnBarUpdate() is not called. I set BarsRequired to 1 and used 'PeriodType.Day' in Add() so that I get one update per day and can get OHLC for that instrument.

          Continued thanks for great support,
          Don

          Comment


            #6
            Don,

            1) This is really up to you. Both methods will provide the same results, I suppose it just depends on how you like see the results.

            2) Try increasing the BarsRequired. This is usually because the bars objects added do not have enough data to complete processing.
            MatthewNinjaTrader Product Management

            Comment


              #7
              Hi Matthew,
              I don't understand - setting the PeriodType to 'Day' and setting the required Bar to 1 should trigger a call to OnBarUpdate for every single day and instrument there is data, i.e. OnBarUpdate should be called once per instrument and day, provided there is data, right?

              Comment


                #8
                Can you post the code you're using?
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  sure:

                  in Initialize():

                  Add("FDAX ##-##",PeriodType.Day,1);
                  <adds about 80 more instruments>
                  BarsRequired = 1;
                  CalculateOnBarClose = true;

                  OnBarUpdate never fires. the instruments. The instruments are all set up with ##-## so can be used consistently

                  Comment


                    #10
                    Are you sure all 80 of these instruments are getting data?

                    If any of these objects are empty, OBU will not be called. You're going to need to simplify the strategy to debug. Try just with one data series added you know you have data for and see if OBU fires.

                    If that works, you'll need to work through all 80 symbols to determine which one is not satisfying the OBU requirement.
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Hi Matthew,

                      the documentation is not clear on this. I quote from the Help Guide:
                      "Since a NinjaScript is truly event driven, the OnBarUpdate() method is called for every bar update event for each Bars object added to a script. This model provides the utmost flexibility."

                      Additionally we need to use BarsInProgress as an index to the CurrentBars and other arrays. This sounds to me that OBU is called for every event. Please confirm.
                      Also, running from SA, Initialize() is sometimes, not always, called twice. Any idea why?

                      Thanks,
                      Don
                      Last edited by nitrox; 12-10-2012, 09:02 PM.

                      Comment


                        #12
                        Hello Don,
                        The OBU will be called whenever the bar gets updated, depending on what CalculateOnBarClose (COBC) you have set. If you have set the COBC to false then it will be updated on every ticks. However if you have set it to true then it will be updated at the end of the bar.

                        In your code you have set CalculateOnBarClose to true, and the bar periodicity is set to Day. With this settings the bars will be updated once, at the end of the day only. If you set the COBC to false then are you able to get it work.


                        Also if you try opening a chart for FDAX ##-## then can you see the chart.


                        Yes, OBU will be called when THAT bar is updated. Say your primary instrument is ES and secondary instrument is FDAX. When ES gets updated then OBU will be called for BarsInProgess == 0, when FDAX gets updated then OBU will be called for BarsInProgess == 1.

                        Yes, Initialize can be called multiple times. If you are trying to calculate something once then we suggest using the OnStartUp event. Please refer to our help guide to know more
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          Hi Joydeep,

                          a few points:

                          a) as you can see from my code example and my description is that COBC is set to true and I want exactly one bar per instrument and trading day to get the OHLC for that instrument and day.
                          I just ran the example for 6E, Australian Dollar, from 1.1.2012 to 11.12.2012. Some days are printed multiple times whiles others are not printed (via

                          Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);
                          Print("BarsInProgress:" + BarsInProgress + ":" + CurrentBars[BarsInProgress]);

                          ) this changes from run to run. What can be the cause of this?


                          b) "Also if you try opening a chart for FDAX ##-## then can you see the chart." - I don't know what you are trying to say - yes, if I open a chart for an instrument I can see that chart.

                          c) There are contradicting messages from Matthew and you. Matthew says that if ANY of the bars for that day are not filled, OBU will NOT be called. You say it will be called if ANY of the bars is filled, i.e. should be called multiple times per day. I think that is correct but why are there different answers to this?

                          d) The HelpGuide states: "The Initialize() method is called once when starting a strategy. This method can be used to configure indicator and strategy properties."
                          As this says "once" - why can initialize be called multiple times when a strategy is started once? A class initialize is called once for each object instantiation, and there should be only one object of the strategy created. Also, from my earlier code you can see I am using Add() which cannot be called from OnStartUp() - why did you suggest I use that?

                          Thanks,
                          Kind regards,
                          Don
                          Last edited by nitrox; 12-11-2012, 11:58 AM.

                          Comment


                            #14
                            Hello Don,
                            a) To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                            Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                            I look forward to assisting you further.

                            *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.



                            b) Thanks for the information. I just want to make sure you connectivity provider providers data for continuous contracts. Also please let me know who you are connected with.

                            c) To be 100% sure please send a toy code as I stated above.


                            d) the help guide further states:
                            Although this method is called once on the start of an indicator or strategy, there are times that this method is also called (Opening an indicator dialog) when you may not expect it to. FOR ADVANCED PROGRAMMERS, DO NOT USE THIS METHOD TO RUN CUSTOM ROUTINES SUCH AS OPENING FORMS, MAKING EXTERNAL CALLS SUCH AS A LICENSE CHECK. PLEASE USE OnStartUp() FOR THOSE PURPOSES.
                            JoydeepNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Tim-c, Today, 03:54 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post Tim-c
                            by Tim-c
                             
                            Started by FrancisMorro, Today, 03:24 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post FrancisMorro  
                            Started by Segwin, 05-07-2018, 02:15 PM
                            10 responses
                            1,771 views
                            0 likes
                            Last Post Leafcutter  
                            Started by Rapine Heihei, 04-23-2024, 07:51 PM
                            2 responses
                            31 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Started by Shansen, 08-30-2019, 10:18 PM
                            24 responses
                            945 views
                            0 likes
                            Last Post spwizard  
                            Working...
                            X