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 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<intSeries_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.Week1);
                }
                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  ValidDataPointTrue
       Friday   Primary Bar Number
    2508   Secondary Bar Number:    0  ValidDataPointFalse
    ----------------------------------------------
       
    Monday   Primary Bar Number2509   Secondary Bar Number:  522  ValidDataPointTrue
      Tuesday   Primary Bar Number
    2510   Secondary Bar Number:  522  ValidDataPointTrue
    Wednesday   Primary Bar Number
    2511   Secondary Bar Number:  522  ValidDataPointTrue
     Thursday   Primary Bar Number
    2512   Secondary Bar Number:  522  ValidDataPointTrue
       Friday   Primary Bar Number
    2513   Secondary Bar Number:    0  ValidDataPointFalse
    ----------------------------------------------
       
    Monday   Primary Bar Number2514   Secondary Bar Number:  523  ValidDataPointTrue
      Tuesday   Primary Bar Number
    2515   Secondary Bar Number:  523  ValidDataPointTrue
    Wednesday   Primary Bar Number
    2516   Secondary Bar Number:  523  ValidDataPointTrue
     Thursday   Primary Bar Number
    2517   Secondary Bar Number:  523  ValidDataPointTrue
       Friday   Primary Bar Number
    2518   Secondary Bar Number:    0  ValidDataPointFalse
    ----------------------------------------------
       
    Monday   Primary Bar Number2519   Secondary Bar Number:  524  ValidDataPointTrue
      Tuesday   Primary Bar Number
    2520   Secondary Bar Number:  524  ValidDataPointTrue
    Wednesday   Primary Bar Number
    2521   Secondary Bar Number:  524  ValidDataPointTrue
     Thursday   Primary Bar Number
    2522   Secondary Bar Number:  524  ValidDataPointTrue
       Friday   Primary Bar Number
    2523   Secondary Bar Number:    0  ValidDataPointFalse
    ----------------------------------------------
       
    Monday   Primary Bar Number2524   Secondary Bar Number:  525  ValidDataPointTrue
      Tuesday   Primary Bar Number
    2525   Secondary Bar Number:  525  ValidDataPointTrue
    Wednesday   Primary Bar Number
    2526   Secondary Bar Number:  525  ValidDataPointTrue
     Thursday   Primary Bar Number
    2527   Secondary Bar Number:  525  ValidDataPointTrue
       Friday   Primary Bar Number
    2528   Secondary Bar Number:    0  ValidDataPointFalse
    ----------------------------------------------
       
    Monday   Primary Bar Number2529   Secondary Bar Number:  526  ValidDataPointTrue
      Tuesday   Primary Bar Number
    2530   Secondary Bar Number:  526  ValidDataPointTrue
    Wednesday   Primary Bar Number
    2531   Secondary Bar Number:  526  ValidDataPointTrue
     Thursday   Primary Bar Number
    2532   Secondary Bar Number:  526  ValidDataPointTrue
       Friday   Primary Bar Number
    2533   Secondary Bar Number:    0  ValidDataPointFalse
    ---------------------------------------------- 

    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 Mongo, Today, 11:05 AM
    0 responses
    1 view
    0 likes
    Last Post Mongo
    by Mongo
     
    Started by Tim-c, Today, 10:58 AM
    0 responses
    1 view
    0 likes
    Last Post Tim-c
    by Tim-c
     
    Started by traderqz, Yesterday, 09:06 AM
    3 responses
    22 views
    0 likes
    Last Post NinjaTrader_ThomasC  
    Started by f.saeidi, Today, 10:19 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by kujista, Today, 06:23 AM
    5 responses
    18 views
    0 likes
    Last Post kujista
    by kujista
     
    Working...
    X