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

Using multiple data series the right way

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

    Using multiple data series the right way

    Hi,

    I am adding multiple data series at
    State.Configure
    to my strategy like so

    AddDataSeries(BarsPeriodType.Minute, 1);
    AddDataSeries(BarsPeriodType.Minute, 5);
    AddDataSeries(BarsPeriodType.Day, 1);
    AddDataSeries(BarsPeriodType.Week, 1);
    AddDataSeries(BarsPeriodType.Month, 1);
    Which chart should I use to execute my strategy?
    What would be the BarsInProgress value respectively for each of the bar types? would it be 0, 1, 2, 3, for 1 min, 5 mins, Day, Week, Month respectively? Which chart interval should select to run the strategy? I prefer 5 mins


    please suggest.
    G


    #2
    Hello gbajaj,

    Thank you for your inquiry.

    The primary data series you choose to execute your strategy on will always be BarsInProgress == 0. The first added data series, in this case a 1 minute series, would be BarsInProgress == 1, the second BarsInProgress == 2, and so on.

    If you're already running the strategy on a 5 minute chart, an additional 5 minute data series would be redundant since you'd have the primary series to get those values from.

    I would highly recommend reviewing this section of our help guide for further tips on using multiple data series in a script:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response!
      I have a better understanding now. The current challenge i am facing right now is that I don't get call back for the day data series i.e. OnBarUpdate . I do see minute and 5 minutes data series call backs though. Bars required do trades is 600 and i can see 1 minutes bar calls for the past few days. Any ideas what i might be missing here?

      Comment


        #4
        Hello gbajaj,

        Thank you for your reply.

        If your strategy is running OnBarClose and you add the following to On Bar Update, do you see prints for each daily bar in the NinjaScript Output window (New > NinjaScript Output)?

        if(BarsInProgress == 3) // note that this is going off the added data series in your above example,
        //if you have changed these you'll need to change the index to the appropriate one for your added daily series
        {
        Print(Time[0] + " on BIP = " + BarsInProgress + " | Close[0]: " + Close[0]);
        }

        You should see a print once per day when the daily bar closes.

        If not, can you give a code sample of what you're trying that doesn't seem to be working for you?

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          I do see that Day and Week now, but Month bar is not printed, I need Month as well.
          Yes i have change the index accordingly.
          Here is the data series :
          AddDataSeries(BarsPeriodType.Minute, 1);
          AddDataSeries(BarsPeriodType.Day, 1);
          AddDataSeries(BarsPeriodType.Week, 1);
          AddDataSeries(BarsPeriodType.Month, 1);
          Since strategy is running on 5 mins chart:
          here are my indices:
          int MINUTES_5 = 0; //Default
          int MINUTE = 1;
          int DAY = 2;
          int WEEK = 3;
          int MONTH = 4;
          Here is the code in onBarUpdate: I am no using onBarClose():
          protected override void OnBarUpdate()
          {

          if (BarsInProgress == MINUTE) {
          if (Bars.IsFirstBarOfSession) {
          MyPrint("OnBarUpdate First Bar Of Session " + BarsInProgress);
          Print(string.Format("Bar number {0} was the first bar processed of the session at {1}. BarinProgress {2}", CurrentBar, Time[0], BarsInProgress));
          }
          return;
          }

          if (BarsInProgress == MINUTES_5 ) {
          //MyPrint(" (BarsInProgress != MINUTES_5 )" + BarsInProgress + " "+ Time[0]);
          //return;
          }

          if (BarsInProgress == DAY ) {
          MyPrint(" Day " + BarsInProgress + " "+ Time[0]);
          return;
          }
          if (BarsInProgress == WEEK ) {
          MyPrint(" WEEK " + BarsInProgress + " "+ Time[0] +" " + Highs[WEEK][0]);
          return;
          }


          if (BarsInProgress == MONTH ) {
          MyPrint(" MONTH " + BarsInProgress + " "+ Time[0]);
          return;
          }

          }
          Here are the out put window dumps:
          6/21/2021 1:20:34 PM: OnStateChange Terminated
          6/21/2021 1:20:34 PM: OnStateChange DataLoaded
          6/21/2021 1:20:34 PM: OnStateChange Historical
          6/21/2021 1:20:34 PM: OnBarUpdate First Bar Of Session 1
          Bar number 0 was the first bar processed of the session at 6/15/2021 3:01:00 PM. BarinProgress 1
          6/21/2021 1:20:34 PM: Day 2 6/16/2021 2:00:00 PM
          6/21/2021 1:20:34 PM: OnBarUpdate First Bar Of Session 1
          Bar number 1364 was the first bar processed of the session at 6/16/2021 3:01:00 PM. BarinProgress 1
          6/21/2021 1:20:34 PM: Day 2 6/17/2021 2:00:00 PM
          6/21/2021 1:20:34 PM: OnBarUpdate First Bar Of Session 1
          Bar number 2729 was the first bar processed of the session at 6/17/2021 3:01:00 PM. BarinProgress 1
          6/21/2021 1:20:34 PM: Day 2 6/18/2021 2:00:00 PM
          6/21/2021 1:20:34 PM: WEEK 3 6/18/2021 2:00:00 PM 14204.75
          6/21/2021 1:20:34 PM: OnBarUpdate First Bar Of Session 1
          Bar number 4094 was the first bar processed of the session at 6/20/2021 3:01:00 PM. BarinProgress 1
          6/21/2021 1:20:34 PM: OnStateChange Transition
          Enabling NinjaScript strategy 'MyInsideDayStrategy/235718546' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
          6/21/2021 1:20:34 PM: OnStateChange Realtime
          6/21/2021 1:20:34 PM: OnStateChange Terminated

          Also I am not able to access Highs[MONTH][0]. How and when should I ensure that I have access to all the bars data before starting a trade?
          Last edited by gbajaj; 06-21-2021, 02:32 PM.

          Comment


            #6
            Hello gbajaj,

            Thank you for your reply.

            If you're only loading 600 5 minute bars on your chart, that wouldn't be enough data loaded to have a 1 month bar. You'd need to load a minimum of a month's worth of data on the chart for there to be any bars in a 1 month series.

            I would try loading say, a year's worth of data on the chart and see the results you get printing the monthly highs.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hi Kate,

              I tried to load 200k Bars by setting BarsRequiredToTrade but it still doesn't have enough bars for monthly.
              Any other suggestoin?

              Thanks
              G

              Comment


                #8
                Hello gbajaj,

                Thank you for your reply.

                Setting BarsRequiredToTrade to 200k would not increase the number of bars loaded on the chart, you'd need to change the amount of data you are loading in the Data Series window. I'd recommend changing BarsRequiredToTrade to 20 (the default) as if you leave it at 200k nothing will occur until after the 200000th bar on the chart of the primary data series.

                Here's an example of loading a year's worth of data in the Data Series window:

                Click image for larger version

Name:	2021-06-25_12-59-33.png
Views:	188
Size:	63.8 KB
ID:	1161440

                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks you!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by gentlebenthebear, Today, 01:30 AM
                  2 responses
                  13 views
                  0 likes
                  Last Post gentlebenthebear  
                  Started by Kaledus, Today, 01:29 PM
                  2 responses
                  8 views
                  0 likes
                  Last Post Kaledus
                  by Kaledus
                   
                  Started by frankthearm, Yesterday, 09:08 AM
                  13 responses
                  45 views
                  0 likes
                  Last Post frankthearm  
                  Started by PaulMohn, Today, 12:36 PM
                  2 responses
                  16 views
                  0 likes
                  Last Post PaulMohn  
                  Started by Conceptzx, 10-11-2022, 06:38 AM
                  2 responses
                  56 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Working...
                  X