Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnEachTick vs OnBarClose

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

    OnEachTick vs OnBarClose

    I have a strategy I’ve written using Calculate = Calculate.OnEachTick but I think it should be Calculate = Calculate.OnBarClose

    The code looks back 2 bars. It compares values in the prior bar (say bar[1]) to the bar before the prior bar (say bar[2]). In this sense, Calculate.OnBarClose should work fine. However, the entry is based on the current bar (say bar[0]) breaking the high or the low of bar[1]. Once that high or low of bar[1] is broken on bar[0], a “EnterLong” or “EnterShort” is true and the trade is entered. My concern on setting this to CalculateOnBarClose is, would the strategy wait until bar[0] closes before the trade is entered OR would the trade still occur on bar[0] once the high or low is broken?

    The problem I am having now with CalculateOnEachTick is if I hit my profit target on the same bar as the entry, the trade fires again even though this new entry is beyond my profit target. My assumption is CalculateOnBarClose will fix this, but I need to confirm it won’t negatively impact the entry logic.

    Thanks

    #2
    Hello CMillz,

    When Calculate is set to 'On each tick' use IsFirstTickOfBar in a condition to trigger actions when the bar closes.


    This is if you want some actions to happen on each tick, and some actions to happen when the bar closes.

    When Calculate is set to 'On each tick' barsAgo 0 (like Close[0]) will refer to the open bar that is currently building.
    When Calculate is set to 'On bar close' barsAgo 0 will refer to the most recently closed bar.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ok...Appreciate the response, but that definitely doesn't answer my question. I had reviewed all of the documents you attached previously before I even posted.

      See the attached picture. The bottom of that pink shaded area is the profit target and the strategy is going long.

      Notice how the first order (circled) enters at the proper level, then almost immediately hits the profit target. However, once the profit target is filled the strategy keeps buying and selling because the logic is true for the remainder of that 5 minute bar.

      I don't want it to keep doing that, I only want it to trade one time. I tried OnBarClose and that doesn't appear to work.

      Comment


        #4
        Sorry picture wasn't attached it seemed
        Attached Files

        Comment


          #5
          Hello CMillz,

          OnBarUpdate will trigger for every tick. The actions that happen are up to your logic.

          If you don't want an action to repeat, use a bool in a condition that prevents the action until the bool is reset.

          Below is a link to an educational site on C#.



          If you want an action to only trigger when a bar is closing, use a condition that checks for IsFirstTickOfBar (which is also a bool).
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          65 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X