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

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.

      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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          6 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          11 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          7 views
          0 likes
          Last Post elirion
          by elirion
           
          Working...
          X