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

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 CortexZenUSA, Today, 12:53 AM
                0 responses
                1 view
                0 likes
                Last Post CortexZenUSA  
                Started by CortexZenUSA, Today, 12:46 AM
                0 responses
                0 views
                0 likes
                Last Post CortexZenUSA  
                Started by usazencortex, Today, 12:43 AM
                0 responses
                2 views
                0 likes
                Last Post usazencortex  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,262 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X