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

Number of bars for each symbol in multi symbol strategy

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

    Number of bars for each symbol in multi symbol strategy

    Hi,

    Assume I have a strategy, that adds two secondary symbols GOOG & APPL on chart.

    What does define the number of bars for GOOG & APPL that are available for the strategy? Are all secondary series aligned with the main series?

    For example, when I create a chart with MSFT as main series, I specify the number of bars/days. I can do the same for the second series when I add it manually.

    However, when I add the second series programmatically via Add() method, there is no option to choose the number of bars/days.

    Questions:
    1. Is it possible to specify number of bars/days for secondary series?
    2. If not, then how the number of bars for the secondary series is determined?


    Thank you!

    #2
    Hello alex.nt,

    Thank you for your post.

    There is no method to determine the number of bars loaded for the secondary and ternary bar series. To ensure you have enough bars before accessing them use CurrentBars and check that the number of bars is as needed. For example:
    Code:
    if(CurrentBars[0] <= BarsRequired II CurrentBars[1] <= BarsRequired)
    return; // ensure we have more bars then the BarsRequired for both the primary (0) and secondary (1) bar series.
    For information on ensuring you have enough bars before accessing them please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

    For information on multiple time frames and instruments in your code please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

    Please let me know if you have any questions.

    Comment


      #3
      But how is the number of bars for the secondary series set by NinjaTrader? There must be a rule for that. Perhaps, it is somehow based on the main series?

      Comment


        #4
        Hello alex.nt,

        Thank you for your response.

        The secondary series will match what the Data Series menu has been set to for the primary series. So if you set the Data Series menu to Load Data Based On - Days and then Days To Load to 1, then both the primary and secondary bar series would only load data for one day. However, if you user Load Data Based On - Bars, then the primary and secondary will both load the number of bars set for Bars To Load. So if I set 500 bars, both the 1 minute (primary) and 60 minute (secondary) bar series will load 500 bars (seen in the example below).

        I created a simple script to test on my end, you can find the code listed below:
        Code:
        		protected override void Initialize()
        		{
        			Add(PeriodType.Minute, 60);
        		}
        
        		/// <summary>
        		/// Called on each bar update event (incoming tick)
        		/// </summary>
        		protected override void OnBarUpdate()
        		{
        			if(CurrentBars[0] <= 0 || CurrentBars[1] <= 0)
        				return;
        			
        			if(BarsInProgress == 0)
        				Print("Primary (1 minute): " + Times[0][0] + " " + CurrentBars[0].ToString());
        			
        			if(BarsInProgress == 1)
        				Print("Secondary (60 minute): " + Times[1][0] + " " + CurrentBars[1].ToString());
        		}
        Please let me know if I may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by frankthearm, Today, 09:08 AM
        7 responses
        30 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by NRITV, Today, 01:15 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by maybeimnotrader, Yesterday, 05:46 PM
        5 responses
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by quantismo, Yesterday, 05:13 PM
        2 responses
        18 views
        0 likes
        Last Post quantismo  
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X