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

Plotting Close more than 10 days ago

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

    Plotting Close more than 10 days ago

    Does the Close function have a limit when plotting as a indicator? I have a formula where I am looking back at the Close from 30 days ago, however, when I tried to plot it came up blank. After some investigation, I determined that plotting Close greater than 9 days will not plot.

    Example:
    This works:
    Plot0.Set (Close[9]);

    This does not:
    Plot0.Set (Close[10]);

    The part of my formula which causes it not to plot is:
    (Close[30] – Close[0]);

    I am hoping this is just a user error on my part. Any help would be appreciated.

    #2
    Hello,

    Thanks for your forum post.

    You need to check and make sure that you have 30 days of data first. Please add the following and change it to 30.



    Let me know if I can be of further assistance.

    Comment


      #3
      My bad, change Days to Minutes. I am using a 1 minute chart. I have 3 months of data loaded.

      Comment


        #4
        Glad to hear your up and running.

        Let me know if I can be of further assistance.

        Comment


          #5
          Still not working

          This is still not working. What am I doing wrong?

          Here is the code:

          if (Close[0] > Close[Math.Min(CurrentBar, 30)])
          Plot0.Set(Close[
          10]);

          See the results in the attached chart. It gives a partial line. The higher you go on the Set(close) the less of a line there is.
          Attached Files

          Comment


            #6
            Originally posted by Silver Dragon View Post
            This is still not working. What am I doing wrong?

            Here is the code:

            if (Close[0] > Close[Math.Min(CurrentBar, 30)])
            Plot0.Set(Close[
            10]);

            See the results in the attached chart. It gives a partial line. The higher you go on the Set(close) the less of a line there is.
            What is your CalculateOnBarClose setting?

            Comment


              #7
              SilverDragon, I would expect that to be the case, as the condition is never true for all the bars in evaluation - so it plots when it triggers as you see on your chart.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Below is the code. I am begining to think there is a bug. I opened a unrelated indicator and changed High[0] to High[12] and would not return any results. This was a functioning indicator. Any lookback period greater than 10 causes issues.

                publicclass CloseTest : Indicator
                {
                #region Variables
                // Wizard generated variables
                privateint myInput0 = 1; // Default setting for MyInput0
                // User defined variables (add any user defined variables below)
                #endregion
                ///<summary>
                /// This method is used to configure the indicator and is called once before any bar data is loaded.
                ///</summary>
                protectedoverridevoid Initialize()
                {
                Add(
                new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay =
                false;
                }
                ///<summary>
                /// Called on each bar update event (incoming tick)
                ///</summary>
                protectedoverridevoid OnBarUpdate()
                {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.

                if (Close[0] > Close[Math.Min(CurrentBar, 30)])
                Plot0.Set(Close[
                10]);
                }

                Comment


                  #9
                  Hello,

                  Your still missing the check to make sure you have enough bars on the chart. To verify this is the case if you check the log tab in the control center you will see an error when you try to run the indicator. You need to add the below code and check to make sure you have 30 bars on the chart before trying to calculate this value.

                  http://www.ninjatrader.com/support/f...ead.php?t=3170

                  Comment


                    #10
                    Brett, I think you mean 10, not 30. He is plotting 10 days ago, so needs at least 10 bars. The 30 bars cannot be an issue, as for less than 30 bars, Math.Min(CurrentBar, 30) will use the smaller value.

                    Comment


                      #11
                      I just looked at your graphic in #5. What it is plotting is exactly what you coded. Let me translate:

                      "If today's close is greater than the close some days ago (if fewer than 30 bars, that number, otherwise, 30 bars ago), then plot the close 10 days ago."

                      Coded that way, it means that if the close today is less than or equal to the close the required number of days ago, there will be no plot.

                      What are you seeking for the plot to be like? Once we know that, maybe we can show you how to achieve your intended effect. It seems that the current effect, while correct from the code, is not what you actually want to be the behavior?

                      Comment


                        #12
                        I put the "if" statement in there because I was trying to fix the problem. I think I made it worse!

                        Maybe I am asking the wrong question. I actually have a formula I am trying to calculate but for simplicity sake lets make it simple; Here is what I want to do:

                        I want a indicator to plot the close from 15 bars ago. So on a one minute chart if it is 3pm I want the indicator to plot the price from 2:45 PM (15 minutes ago).

                        I thought I could just put Plot0.Set(Close[15])

                        Is this not right?

                        Comment


                          #13
                          Originally posted by Silver Dragon View Post
                          I put the "if" statement in there because I was trying to fix the problem. I think I made it worse!

                          Maybe I am asking the wrong question. I actually have a formula I am trying to calculate but for simplicity sake lets make it simple; Here is what I want to do:

                          I want a indicator to plot the close from 15 bars ago. So on a one minute chart if it is 3pm I want the indicator to plot the price from 2:45 PM (15 minutes ago).

                          I thought I could just put Plot0.Set(Close[15])

                          Is this not right?
                          Yes, provided you have ensured that (CurrentBar >= 15). If you do not, you will get an indexing exception which will show up in the log.

                          Comment


                            #14
                            OK here is where I need guidance;

                            I have a 1 minute chart with 3 months worth of data loaded. (Dec - Feb). When I plot
                            Plot0.Set(Close[15]); the indicator comes back blank and it throws the index error you mentioned. Logically (in my brain) this does not make sense. The chart has 100,000 bars on it. How can there not be enough bars to plot the close from 15 bars ago??


                            Comment


                              #15
                              Originally posted by Silver Dragon View Post
                              OK here is where I need guidance;

                              I have a 1 minute chart with 3 months worth of data loaded. (Dec - Feb). When I plot
                              Plot0.Set(Close[15]); the indicator comes back blank and it throws the index error you mentioned. Logically (in my brain) this does not make sense. The chart has 100,000 bars on it. How can there not be enough bars to plot the close from 15 bars ago??


                              On bar0, (actually until bar15), there will not be any bar 15 bars ago. So the exception is being thrown right at the beginning of your indicator.

                              The easiest way to ensure that you have the correct number of bars at all times, is to not process the class update functions unless you have enough bars. Most of us just put this as the first statement in OnBarUpdate().

                              Code:
                              if (CurrentBar < 15) return;
                              But you must put it where it logically belongs. In other words, if you are processing stuff before 15 bars, (eg., on bar0), then obviously this must come after those processes.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X