• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

wrong Bars.Get(CurrentBar).Close value

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

    wrong Bars.Get(CurrentBar).Close value

    Hello,

    has someone a hint why "Close" values differ in this example:

    Code:
    using NinjaTrader.Data;
    
    public class CloseDiffTest : NinjaTrader.Indicator.Indicator {
        protected override void Initialize() {
            Add(PeriodType.Tick, 1);
        }
        protected override void OnBarUpdate() {
            if (BarsInProgress == 1) {
                IBar bar = BarsArray[BarsInProgress].Get(CurrentBar);
    
                // Close[0] != bar.Close // why???            
                var diff1 = bar.Open - bar.Close;
                var diff2 = Open[0] - Close[0];
    
                if (diff1 != 0 && diff2 == 0) {
                    Print(diff1 + " -> " + diff2);
                }
            }
        }
    }
    output:

    Code:
    ...
    -2 -> 0
    -3 -> 0
    -2 -> 0
    -2 -> 0
    -1 -> 0
    -1 -> 0
    -1 -> 0
    ...

    #2
    Originally posted by foobar View Post
    Hello,

    has someone a hint why "Close" values differ in this example:


    [/CODE]
    False syntax, try:

    Code:
    protected override void OnBarUpdate() {
            if (BarsInProgress == 1) {
                IBar bar = BarsArray[BarsInProgress].Get(CurrentBars[BarsInProgress]);
    
                // Closes[BarsInProgress][0] != bar.Close // why???            
                var diff1 = bar.Open - bar.Close;
                var diff2 = Opens[BarsInProgress][0] - Closes[BarsInProgress][0];
    
                if (diff1 != 0 && diff2 == 0) {
                    Print(diff1 + " -> " + diff2);
                }
            }
        }

    Comment


      #3
      Hello foobar,

      Harry is correct here.
      Patrick H.NinjaTrader Customer Service

      Comment


        #4
        Hello Harry,

        Thanks for the answer!
        This does not help. Same wrong values.

        Code:
        using NinjaTrader.Data;
        
        public class CloseDiffTest : NinjaTrader.Indicator.Indicator {
            protected override void Initialize() {
                Add(PeriodType.Tick, 1);
            }
            protected override void OnBarUpdate() {
                if (BarsInProgress == 1) {
                    IBar bar = BarsArray[BarsInProgress].Get(CurrentBars[BarsInProgress]);
        
                    var diff1 = bar.Open - bar.Close;
                    var diff2 = Opens[BarsInProgress][0] - Closes[BarsInProgress][0];
        
                    if (diff1 != 0 && diff2 == 0) {
                        Print(diff1 + " -> " + diff2);
                    }
                }
            }
        }
        The wrong value is "bar.Close" and only for PeriodType.Tick of 1. For PeriodType.Tick of 2 there is no problem.

        Code:
        //Add(PeriodType.Tick, 1);
        Add(PeriodType.Tick, 2);
        It's not a big problem. I have replaced all "Close" with "Open" for PeriodType.Tick of 1. However it's somewhat troublesome.

        @NinjaTrader_PatrickH: Please confirm this as a bug.

        Comment


          #5
          Hello foobar,

          Thank you for your patience.

          There is fundamental caching involved in building the bars and IBar is using the bars cached in memory, with such a small granularity it would not work for your example.

          If you need the 1 Tick data, just use Add() as this will ensure the data is cached in the correct manner for accessing bar values (example: Close[0], Open[0], etc.).

          Please let me know if you have any questions.
          Patrick H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by saeed, Today, 12:32 PM
          3 responses
          20 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by motog4, Today, 11:42 AM
          3 responses
          12 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by derivtrader, Today, 11:20 AM
          5 responses
          26 views
          0 likes
          Last Post derivtrader  
          Started by TAJTrades, Today, 10:34 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by timcjpfx, Today, 10:20 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X