Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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#.
          Test the bool type, which holds true or false. A bool occupies 1 byte of memory.



          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 junkone, Today, 11:37 AM
          0 responses
          2 views
          0 likes
          Last Post junkone
          by junkone
           
          Started by quantismo, 04-17-2024, 05:13 PM
          5 responses
          34 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by proptrade13, Today, 11:06 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          34 views
          0 likes
          Last Post love2code2trade  
          Started by cls71, Today, 04:45 AM
          2 responses
          10 views
          0 likes
          Last Post eDanny
          by eDanny
           
          Working...
          X