Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Failing to access the Inter-Bar Granularity with MultiSeries Strategy...

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

    Failing to access the Inter-Bar Granularity with MultiSeries Strategy...

    Hello Ninjascript community!
    Let me begin by saying that I do not want to annoy anyone and so I have read all of the posts and documentation about programming the intra-bar granularity

    Click image for larger version

Name:	Intrabar Granularity.png
Views:	144
Size:	5.0 KB
ID:	1306290

    I understand the way the bar series is determined is by the first parameter: 0 = primary bars,1 = secondary bars, 2 = tertiary bars, etc. */

    However the examples on this forum for Multi-Instrument show functions which are no longer in the current version of NinjaTrader and so I'm confused.
    Drawing from the experience of this past explanation let us revisit a EMA crossover example
    IsFirstTickOfBar vs OnBarClose for backtest & live - NinjaTrader Support Forum​

    Code:
    AddDataSeries(Data.BarsPeriodType.Tick, 500);
    AddDataSeries("ES 06-24",Data.BarsPeriodType.Tick, 500);
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    ​
    For the crossover EMA example, suppose we must open a position when the EMA crossover happens on a 500 tick chart of the current instrument regardless of what size of chart of the current instrument that the user happens to be looking at... So the user could be looking at a 1000 tick chart, a 1500 tick chart etc but the EMA will be scaled to the 500 tick series

    AND the last ES 500 tick Bar closes Above/Below the preceding ES 500 tick


    Then lastly as is documented we must execute the orders on a the 1 tick Inter-Bar Granularity...

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class SampleIntrabarBacktest : Strategy
        {
            private int    fast;
            private int    slow;
    
            protected override void OnStateChange()
            {
                if(State == State.SetDefaults)
                {                
                    Fast            = 10;
                    Slow            = 50;    
                    Calculate        = Calculate.OnEachTick;
                    Name            = "SampleIntrabarBacktest";
                }
                
                else if(State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 500);
                    AddDataSeries("ES 06-24",Data.BarsPeriodType.Tick, 500);
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                    
                    // Add two EMA indicators to be plotted on the primary bar series
                    AddChartIndicator(EMA(Fast));
                    AddChartIndicator(EMA(Slow));
                    
                    
                    EMA(Fast).Plots[0].Brush = Brushes.Yellow;
                    EMA(Slow).Plots[0].Brush = Brushes.Orange;
                }
            }
    
            protected override void OnBarUpdate()
            {
                        
                /*
                When the OnBarUpdate() is called from the primary bar series, do the following
                */
                if (BarsInProgress == 1)
                {
                    /// When the fast EMA crosses above the slow EMA, AND the last ES 500 tick Bar closes Higher than preceding ES 500 tick GO long on the 1 tick InterBar bar series
                    if ( CrossAbove(EMA(Fast), EMA(Slow), 1) ) //&& Closes[?][1] >= Closes[?][2] ??? Suppose I also wish to see the ES 500 tick does that go here? I am being silly
                    {
                        EnterLong(3, 1, "Long: 1 tick InterBar");
                    }
                    /// When the fast EMA crosses below the slow EMA, AND the last ES 500 tick Bar closes Higher than preceding ES 500 tick GO short on the 1 tick InterBar bar series
                    else if ( CrossBelow(EMA(Fast), EMA(Slow), 1) ) //&& Closes[?][1] <= Closes[?][2] ??? Suppose I also wish to see the ES 500 tick does that go here? I am being silly
                    {
                        // The entry condition is triggered on the primary bar series, but the order is sent and filled on the 1 tick InterBar,
                        EnterShort(3, 1, "Short: 1 tick InterBar");
                    }
                }
                
            }​
    Please see the attached NinjaScript Strategy

    #2
    In my actual indicators and strategies I must define several items inside the (State == DataLoaded) section

    Code:
    else if (State == State.DataLoaded)
     {​
    blahBlah=BlahBlah(Close, intFAST, intSLOW);
    dynamicTickingES = DynamicTickingES(BarsArray[1]);
    }
    I will sort all these out oncve I understand how to use the Inter-Bar Granularity with the Multi-Instrument Chart.
    The videos from NinjaTrader 7 confuse me with the legacy information otherwise I would not be bothering the Forum...

    The videos were enjoyable however I find myself lost in legacy information

    Comment


      #3
      The video and the many threads from Ninja Trader 7 were very well made unfortunately I was not able to find how to use an Inter-Bar Granularity for Multi-Instrument Strategies in Ninja Trader 8
      Code:
      else if (State == State.Configure)
       {        
      AddDataSeries("ES 06-24", Data.BarsPeriodType.Tick, 2000);  
      AddDataSeries(Data.BarsPeriodType.Tick, 1);
      }
      Last edited by DynamicTest; 06-06-2024, 03:39 AM.

      Comment


        #4
        Hello DynamicTest,

        Thank you for your post.

        The SampleIntrabarBacktest script you have posted demonstrates how you can implement intrabar granularity in your script. You would need to manually add the single-tick data series via AddDataSeries(), then submit the orders to the more granular series in the same fashion demonstrated in the script.



        Your condition can still check for information from the primary or any 500 tick series, but the orders should be submitted to the single-tick data series.

        "the last ES 500 tick Bar closes Higher than preceding ES 500 tick GO long on the 1 tick InterBar bar series"

        Since the 500 tick series is the secondary series, checking if Closes[1][1] > Closes[1][2] would compare if the closing price of the previous 500 tick bar (1 bar ago) is greater than the close price of the bar before that (2 bars ago).




        I'm not seeing any outdated information in the forum post linked. Can you please clarify what exactly you are having trouble with regarding implementing intrabar granularity, or what part of the forum post is not clear?

        Comment


          #5
          Originally posted by NinjaTrader_Gaby View Post
          Hello DynamicTest,

          Thank you for your post.

          The SampleIntrabarBacktest script you have posted demonstrates how you can implement intrabar granularity in your script. You would need to manually add the single-tick data series via AddDataSeries(), then submit the orders to the more granular series in the same fashion demonstrated in the script.



          Your condition can still check for information from the primary or any 500 tick series, but the orders should be submitted to the single-tick data series.

          "the last ES 500 tick Bar closes Higher than preceding ES 500 tick GO long on the 1 tick InterBar bar series"

          Since the 500 tick series is the secondary series, checking if Closes[1][1] > Closes[1][2] would compare if the closing price of the previous 500 tick bar (1 bar ago) is greater than the close price of the bar before that (2 bars ago).




          I'm not seeing any outdated information in the forum post linked. Can you please clarify what exactly you are having trouble with regarding implementing intrabar granularity, or what part of the forum post is not clear?

          Thank you very much.
          The notation which I found ambiguous in the forum I resolved by using multiple steps
          Code:
          if (BarsInProgress==0)
          {
          }
          if (BarsInProgress==1)
          {
          }
          if (BarsInProgress==2)
          {
          }
          Otherwise the script would be restricted to chart sizes which would be larger or smaller than some of the AddSeries() sizes...


          Thank You again for the confirming the syntax so I could feel confident to continue debugging!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          116 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          61 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          40 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          43 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          82 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X