Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy using Multiple TimeFrames and DataSeries

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

    Strategy using Multiple TimeFrames and DataSeries

    How would I sync a DataSeries created within a Multi Time Frame Strategy to a specific Time Interval. For learning purposes this Strategy is placed on a 500 Volume chart. I am trying to create a 5 Minute SMA(10) from within the Strategy. I know that I can just go get the SMA from an indicator but that is not the purpose here. There are other Calculations that I need that are not in an Indicator.

    How can I sync the DataSeries fiveMinuteSMA to BarsArray[2]? This code does not work.



    PHP Code:
        public class MTFIndicators : Strategy
        {
            #region Variables
            
                private DataSeries fiveMinuteSMA;         // Value of 5 Minute SMA    
            
            #endregion
    
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
                BarsRequired = 0;
                
                Add(PeriodType.Minute, 1);     // BarsArray[1]
                Add(PeriodType.Minute, 5);     // BarsArray[2]
                Add(PeriodType.Minute, 15);     // BarsArray[3]
                
                fiveMinuteSMA = new DataSeries(this);   // Sync this Series to the 5 Minute Bars
                
            }
    
    
            protected void FiveMinuteIndicatorValues()
            {
                Print(Time[0].ToString() + "\tM5\t" + CurrentBar.ToString() );    
                
                //  Calulate a 10 Period SMA
                int Period = 10;  //SMA Period
                
                if (CurrentBar == 3)        //  Bar #3 shows as the 1st Bar when Adding 15 Min Bars to the Strategy
                    fiveMinuteSMA.Set(Inputs[2][0]);  // First 5 Min Bar.  Set SMA Value to Close.
                else
                {
                    double last = fiveMinuteSMA[1] * Math.Min(CurrentBar, Period);
                    if (CurrentBar >= Period)
                        fiveMinuteSMA.Set((last + Inputs[2][0] - Inputs[2][Period]) / Math.Min(CurrentBar, Period));
                    else
                        fiveMinuteSMA.Set((last + Inputs[2][0]) / (Math.Min(CurrentBar, Period) + 1));
                }
            }
            
            protected override void OnBarUpdate()
            {
                if (BarsInProgress == 2)
                {
                    FiveMinuteIndicatorValues();
                }
            } 
    
    Thanks for any suggestions.

    #2
    Hi TAJTrades, have you seen the sample titled Synchronizing a DataSeries object to a secondary time frame?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks Austin. I failed to import a couple of Sample Scripts and that was one of them. Exactly what I needed because I was trying to do it exactly the wrong way.

      NT Support Folks are fantastic.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X