Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsArray Intrabar Synchronization

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

    BarsArray Intrabar Synchronization

    I am looking to place orders on the primary bar series (5 min) yet take trading signals based on the most recent secondary higher timeframe bar series (30 min) values and indicator conditions. I also wanted to use an assigned dataseries to enable flexibility in selecting the moving average indicator I use as specified in a parameter setting. Please see the sample code and questions below:

    Code:
    private DataSeries ExitMAfast; 
    private DataSeries ExitMAslow; 
    
    protected override void Initialize()
    {
         ExitMAfast = new DataSeries(this);
         ExitMAslow = new DataSeries(this)
    }
    
    protected override void OnBarUpdate()
    {
         if (BarsInProgress == 1) 
         {
              If (MovingAverageType == 1)
              {
                   ExitMAfast.Set(EMA(exitMAPeriodFast)[0]);
                   ExitMAslow.Set(EMA(exitMAPeriodSlow)[0]);	
              }
              else
              {
                   ExitMAfast.Set(HMA(exitMAPeriodFast)[0]);
                   ExitMAslow.Set(HMA(exitMAPeriodSlow)[0]);
              }				
         }
         if (BarsInProgress == 0) 
         {
         ...
              if (Position.MarketPosition == MarketPosition.Long &&
                  CrossBelow(ExitMAfast, ExitMASlow, 1))
              {
                   ExitLong();						
              }
         ...
         }
    }
    1. While backtesting in OnBarClose mode, if there is a primary bar (5 min) close event and there is a secondary bar (30 min) intra-bar moving average crossover condition, I would like to initiate a exit trading signal. In other words, after three 5 minute primary bars have printed, can you also determine the intra-bar value halfway through the 30 minute secondary bar, as well as any indicator values that have been defined on that secondary bar (BarsArray[1])?
      -
    2. How does this answer differ for real-time vs backtesting and OnTickClose vs OnBarClose?
      -
    3. As you can see in the code, I am trying to use a dataseries to selectively assign the indicator values for the higher time frame indicators while BarsInProgress = 1 so that I can use these values to initiate a trading signal (Exit) when BarsInProgress = 0. This approach doesn't seem to work and its unclear whether a private dataseries cannot be used in this manner or its a limitation with the CrossAbove/Below functions. Any suggestions?


    The true event based multiple-instrument/timeframe functionality is a very compelling and useful feature . . . thanks for being ahead of the curve on this.

    Regards,

    Whitmark
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    #2
    1) No, since there is no concept of intrabar values in a backtest. The resolution is ALWAYS at the bar level thus, you will always see the last bar closed.

    2) If you run with CalculateOnBarClose == false in real-time, you will always be pointing to the current bar in formation, thus you can see the intrabar value on the secondary series.

    3) This approach is no different that accessing the indicator values directly since all you are doing is saving the value of the last bar close.
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks, Ray, for the timely response . . . it helps confirm what I was expecting.
      whitmark
      NinjaTrader Ecosystem Vendor - Whitmark Development

      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