Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to modify Range Indicator to display Today Current Close minus Yesterday Close

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

    Trying to modify Range Indicator to display Today Current Close minus Yesterday Close

    Hello,

    I am trying to modify the built in Range Indicator for use on daily bar where it would display the difference between the current close and yesterday close instead of today high minus today low.

    I tried the following simple modification but it doesn't work.

    Value.Set(Close[0] - Close[1]);

    Thanks

    #2
    Hello tuanly,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Have you tried setting the CalculateOnBarClose to False?

    For information on CalculateOnBarClose please visit the following link: http://www.ninjatrader.com/support/h...onbarclose.htm

    Please let me know if you have any questions.

    Comment


      #3
      Hi Patrick,

      Thanks for the quick reply.

      I tried it with CalculateOnBarClose = false and nothing still happens

      This is my code:

      protected override void Initialize()
      {
      CalculateOnBarClose = false;
      Add(new Plot(Color.Firebrick, PlotStyle.Bar, "Close2Close"));
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {

      Value.Set(Close[0] - Close[1]);

      }

      I checked by seeing if it worked by changing the code to Value.Set(Close[0] - Open[0]); and it does. So im guessing there must be something missing regarding pulling yesterday close?

      Comment


        #4
        Hello tuanly,

        Thank you for your response.

        Do you see any errors listed in the log tab of the NinjaTrader Control Center?

        If so please detail in your response.

        Comment


          #5
          Hi Patrick,

          Their is an error, here is the log message.

          Error on calling 'OnBarUpdate' method for indicator 'Close2Close' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

          Comment


            #6
            Originally posted by tuanly View Post
            Hello,

            I am trying to modify the built in Range Indicator for use on daily bar where it would display the difference between the current close and yesterday close instead of today high minus today low.

            I tried the following simple modification but it doesn't work.

            Value.Set(Close[0] - Close[1]);

            Thanks
            What is the error in your log?

            I expect it to say: "You are accessing an index with a value that is invalid since its out of range", in which case you need to escape your first bar.

            In which case, I would suggest that you look at my response in this tread.

            ref: http://www.ninjatrader.com/support/f...ape+currentbar

            Comment


              #7
              Hello tuanly,

              Thank you for your response.

              Your error is what koganam has expected to see. Please review the information at the following link on making sure you have enough bars before accessing them: http://www.ninjatrader.com/support/f...ead.php?t=3170

              Please let me know if I may be of further assistance.

              Comment


                #8
                Thank you both for your help, it solved my problem.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                581 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                338 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                552 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X