Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnEachTick but indi use closed bars only?

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

    OnEachTick but indi use closed bars only?

    My strategy calculates OnEachTick, but one of my indicators really needs to calculate only OnBarClose.

    I tried adding check for IsFirstTickOfBar to indicator's OnBarUpdate, but that didn't help. I guess it's because it's receiving tick data from the parent (strategy) so it sees each tick as a new "bar"

    Is the only solution to create a custom closed-bars-only data series in my strategy like "closedBarsOnly15Sec" and pass that to my indicator? Or can I somehow pass BarsArray[0] but NOT including the current open bar 0?
    Last edited by iantriestrading; 03-20-2025, 10:44 AM.

    #2
    Hello iantriestrading,

    Thank you for your post.

    Within the strategy, only call the indicator / get the indicator value when IsFirstTickOfBar is true. This will allow you obtain the value once per bar (onbarclose essentially).

    Please let us know if you have any further questions.

    Comment


      #3
      Hi Gaby, unfortunately when provided tick data, the indicator provides wrong information, so I need to feed it closed bars only. Any other solutions?

      I'm already doing this:

      if (BarsInProgress == 0 && IsFirstTickOfBar) {

      myIndicator.Update();

      }

      But somehow the calculation is still off.. hmm


      UPDATE:

      I added vars for bar indexes in my indicator and set them dynamically depending on the calculate method the indicator is using. By default, it uses onBarClose, but when it is in a strategy that uses onEachTick, it was working with current open bar because it's receiving data on IsFirstTickOfBar...
      Code:
      // Set the bar indices based on calculation mode
      if (Calculate == Calculate.OnBarClose)
      {
      // When running on bar close, bars 0, 1, 2 are all complete
      bar1Index = 2; // First bar in pattern (oldest)
      bar2Index = 1; // Middle bar
      bar3Index = 0; // Most recent bar (newest)
      }
      else // Calculate.OnEachTick or Calculate.OnPriceChange
      {
      // When running on first tick of bar, bar 0 is just opening
      // So we need to look at bars 1, 2, 3 which are all complete
      bar1Index = 3; // First bar in pattern (oldest)
      bar2Index = 2; // Middle bar
      bar3Index = 1; // Most recent complete bar
      }
      ​
      Then in my indicator code instead of doing like... dataSeries[2] I would do dataSeries[bar2Index]

      This is working now
      Last edited by iantriestrading; 03-20-2025, 12:26 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X