Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate.OnBarClose and index [0]

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

    Calculate.OnBarClose and index [0]

    Hi, I've just bought a lifetime license and I am testing few basics.


    I've done some tests that indicate me that depending on the Calculate setting accessing the index [0] points to a different bar.

    1. Calculate.OnBarClose ->> inside the OnBarUpdate method, [0] points to the recently closed bar, not to the recently opened new bar.

    2. Calculate.OnEachTick ->> inside the OnBarUpdate method, [0] points always to the current bar regardless is closed or still developing. This means that you'll never get the recently closed bar values accessing through the [0] index.

    This creates an inconsistent behaviour using the series indexes [0] ...
    Am I correct?
    (I've read and reread all the docs several times and multiple posts)

    #2
    Originally posted by joanrocagas View Post

    2. Calculate.OnEachTick ->> inside the OnBarUpdate method, [0] points always to the current bar regardless is closed or still developing. This means that you'll never get the recently closed bar values accessing through the [0] index.
    Use [1] to get the previous bar, [2] the bar before that, etc.

    Comment


      #3
      Thanks sledge,

      I think I know how the indexing works and how to access the previous bar. The problem is in some cases [0] is the current bar and in others it is the previous bar. Similarly to the problems explained here:

      Comment


        #4
        I don't see the problem.

        Add SMA to the chart and run it in each mode.

        OnBarClose is always one behind until the current bar closes. It's how the system is designed.

        Don't get caught up in others confusion.

        Comment


          #5
          Hello joanrocagas,

          Thanks for your posts.

          As member sledge has advised, the modes are designed that way and the references have to change accordingly. Calculate.OnEachTick allows you access to the current right edge of chart data. Calculate.OnEachBar provides access to the latest complete bar.

          Using OnEachBar provides data that does not change and allows the script to run once per bar. Using OnEachTick provides data that changes on each tick and causes your script to also run on each tick. This mode is more cpu/resource intensive and is why, be default, most indicators are set to run OnEachBar.

          Which mode you use depends on your needs.

          It is also possible to effectively use both modes as demonstrated in the working example here: http://ninjatrader.com/support/forum...ad.php?t=19387
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,265 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          12 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X