Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Time Frame with private Series

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

    Multi Time Frame with private Series

    Here is a simple indicator script using a private series on the secondary series.
    The Chart is a Daily Chart using NT's EOD Stock Data the Secondary series a Weekly Series. I choose this to keep things a simple as possible.


    PHP Code:
        public class tajTestMTF : Indicator
        {
            private Series<int> Series_WeekBarNumber;
    
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "tajTestMTF";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                    ClearOutputWindow();
    
                    AddDataSeries(Data.BarsPeriodType.Week, 1);
                }
                else if (State == State.DataLoaded)
                {            
                    Series_WeekBarNumber = new Series<int>(BarsArray[1], MaximumBarsLookBack.Infinite);
    
    
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(BarsInProgress == 0)
                {
                    Print(string.Format("{0,9}   Primary Bar Number: {1,4}   Secondary Bar Number: {2,4}  ValidDataPoint: {3}",
                        Time[0].DayOfWeek,
                        CurrentBar,
                        Series_WeekBarNumber[0],
                        Series_WeekBarNumber.IsValidDataPointAt(CurrentBars[1])
                        ));
    
                    if(Times[0][0].DayOfWeek == DayOfWeek.Friday)
                        Print("----------------------------------------------");
                }
                if(BarsInProgress == 1)
                {
                    if(CurrentBar >= 0)
                     Series_WeekBarNumber[0] = CurrentBar;
    
                }
    
    
            }
        } 
    
    and the OutputWindow showing the results
    PHP Code:
    
     Thursday   Primary Bar Number: 2507   Secondary Bar Number:  521  ValidDataPoint: True
       Friday   Primary Bar Number: 2508   Secondary Bar Number:    0  ValidDataPoint: False
    ----------------------------------------------
       Monday   Primary Bar Number: 2509   Secondary Bar Number:  522  ValidDataPoint: True
      Tuesday   Primary Bar Number: 2510   Secondary Bar Number:  522  ValidDataPoint: True
    Wednesday   Primary Bar Number: 2511   Secondary Bar Number:  522  ValidDataPoint: True
     Thursday   Primary Bar Number: 2512   Secondary Bar Number:  522  ValidDataPoint: True
       Friday   Primary Bar Number: 2513   Secondary Bar Number:    0  ValidDataPoint: False
    ----------------------------------------------
       Monday   Primary Bar Number: 2514   Secondary Bar Number:  523  ValidDataPoint: True
      Tuesday   Primary Bar Number: 2515   Secondary Bar Number:  523  ValidDataPoint: True
    Wednesday   Primary Bar Number: 2516   Secondary Bar Number:  523  ValidDataPoint: True
     Thursday   Primary Bar Number: 2517   Secondary Bar Number:  523  ValidDataPoint: True
       Friday   Primary Bar Number: 2518   Secondary Bar Number:    0  ValidDataPoint: False
    ----------------------------------------------
       Monday   Primary Bar Number: 2519   Secondary Bar Number:  524  ValidDataPoint: True
      Tuesday   Primary Bar Number: 2520   Secondary Bar Number:  524  ValidDataPoint: True
    Wednesday   Primary Bar Number: 2521   Secondary Bar Number:  524  ValidDataPoint: True
     Thursday   Primary Bar Number: 2522   Secondary Bar Number:  524  ValidDataPoint: True
       Friday   Primary Bar Number: 2523   Secondary Bar Number:    0  ValidDataPoint: False
    ----------------------------------------------
       Monday   Primary Bar Number: 2524   Secondary Bar Number:  525  ValidDataPoint: True
      Tuesday   Primary Bar Number: 2525   Secondary Bar Number:  525  ValidDataPoint: True
    Wednesday   Primary Bar Number: 2526   Secondary Bar Number:  525  ValidDataPoint: True
     Thursday   Primary Bar Number: 2527   Secondary Bar Number:  525  ValidDataPoint: True
       Friday   Primary Bar Number: 2528   Secondary Bar Number:    0  ValidDataPoint: False
    ----------------------------------------------
       Monday   Primary Bar Number: 2529   Secondary Bar Number:  526  ValidDataPoint: True
      Tuesday   Primary Bar Number: 2530   Secondary Bar Number:  526  ValidDataPoint: True
    Wednesday   Primary Bar Number: 2531   Secondary Bar Number:  526  ValidDataPoint: True
     Thursday   Primary Bar Number: 2532   Secondary Bar Number:  526  ValidDataPoint: True
       Friday   Primary Bar Number: 2533   Secondary Bar Number:    0  ValidDataPoint: False
    ---------------------------------------------- 
    

    So the question is why on Fridays is the Secondary Bar Number always 0. Shouldn't that number be the same as the Thursday number?
    If I read the Help Guide correctly when the Primary and Secondary have the same DateTime Stamp which they will on Friday's then the Primary is processed first which means the Secondary Bar number has not been updated and should be the same as the preceding Thursday. Only after the BIP[1] has been processed then the Series_WeekBarNumber should be updated and reflected on the following Monday.

    Where am I going wrong?

    Thanks.
    Attached Files
    Last edited by TAJTrades; 07-14-2019, 06:34 AM.

    #2
    Hello TAJTrades,

    If you are just printing the value of CurrentBar during BarsInProgress 1, are you seeing that CurrentBar is printing a 0 after the first bar has already processed?
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    596 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    554 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X