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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      54 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X