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

cumulative index

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

    cumulative index

    Hi, I'm trying to create a cumulative index but what I've been able to get so far are individual plots joined up by a line. I'm not quite sure how to get the values to add up. Would you mind helping? Thanks!
    Attached Files

    #2
    Hi, no love for me today?

    Comment


      #3
      Not sure I follow what you mean by 'cumulative' index, you could also do this with one plot / dataseries only thus having the continuity.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        what I want to do is have the data calculated to be added together with a base at zero.

        So starting from a base of zero, after the first bar is complete, we add the data calculated based on the first bar to zero. This forms the new base. Then we add on the data that is calculated from the second bar to the new base. This goes on ad infinitum. The only thing to note is the denom does not equal zero.

        I can't get these pieces of data calculated from each bar to add....

        Comment


          #5
          I see thanks - then I would suggest taking a look at the EMA indicator as example for such a technique, it builds a cumulative value with previous dataseries value (' * Value[1] ' part).

          Code:
           
          {
          Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
          }
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hi Bertrand, It's similar in a way. It differs in that there are 1 value to use if true and another value to use if false. The cumulative index I am trying to create just adds the values calculated. Plus I'm not sure how to fit in the formula have have in the manner set out by EMA Indicator.

            As you know, my formula is ((Close[0]-Open[0])/(Math.Max(High[0],Close[1]))-(Math.Min(Low[0],Close[1]))). That is essentially what is in the code. And the denominator>0.

            Would appreciate your help if you wouldn't mind...thanks!

            Comment


              #7
              All you would need to do then is set value A when conditions for A are true, otherwise set value B.

              You can use a simple if-else statement to achieve this.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Thanks Josh. Will try that out tomorrow morning. Have a pleasant evening guys!

                Comment


                  #9
                  Josh/Bertrand,

                  When I compile the code, no errors appear but no output occurs too!

                  I tried to narrow down the possibilities and it seems it's the DataSeries that is not producing any output. Below is the code for the DataSeries:-

                  myDataSeries.Set((Close[0]-Open[0])/((Math.Max(High[0],Close[1]))-(Math.Min(Low[0],Close[1]))));

                  if (CurrentBar < 2)

                  Print(
                  "The values are " + myDataSeries[0] + " " + myDataSeries[1]);

                  Why isn't there any output? Could you guys please take a look? Do I need to type anything in the "Properties" section?
                  Thanks!

                  Just remembered to check the log...there was this message..."Error on caling the 'OnBarUpdate'method fot the indicator 'draftpresscum' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection." What does this mean?
                  Last edited by kaywai; 01-27-2010, 02:30 AM.

                  Comment


                    #10
                    Josh/Bertrand,

                    Tried to narrow the error down further. The part that is creating the error log ..."Error on caling the 'OnBarUpdate'method fot the indicator 'draftpresscum' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection."...is this part:-

                    myDataSeries2.Set(Math.Max(High[0],Close[1])-(Math.Min(Low[0],Close[1])));

                    I can't even generate data from this line and it's not even a denominator in this case! Please help.

                    Comment


                      #11
                      Kay, you would need to place the current bar check at the OnBarUpdate() start, otherwise you access Close[1] on the first bar of the chart, which is not defined and thus gives you this issue then.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Bertrand, I did what you instructed and it works fine but when I substitute this code in its place

                        if (CurrentBar > 2 )

                        myDataSeries.Set((Close[0]-Open[0])/((Math.Max(High[0],Close[1]))-(Math.Min(Low[0],Close[1]))));

                        This error message pops up: "Error on plotting indicator 'draftpresscum'. Please check the 'OnBarUpdate' or the 'Plot' method: Overflow error."

                        BTW this is still part of the cumulative index i'm still struggling with...


                        Comment


                          #13
                          Most likely you see this error because of a divivde by zero error in the denominator of your equation.

                          You can check into the default Stochastic's indicator K.Set code to see how to check for those occurences...
                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Got that sorted out. Now to sort the cumulation bit...

                            Comment


                              #15
                              Guys, writing the cumulative index code has been the most frustrating to date. The code below is what I thought would help me achieve it but:-

                              if (CurrentBar > 2 )
                              myDataSeries1.Set((Close[
                              0]-Open[0])/(((Math.Max(High[0],Close[1]))-(Math.Min(Low[0],Close[1])))!= 0? (Math.Max(High[0],Close[1])-(Math.Min(Low[0],Close[1]))):1.0));
                              Upper.Set(myDataSeries1[
                              0]);

                              Value.Set(
                              0);
                              if (Close[0]>Open[0])
                              Value.Set(Value[
                              1]+Upper[0]);
                              elseif (Close[0]<Open[0])
                              Value.Set(Value[
                              1]+Upper[0]);
                              else
                              Value.Set(Value[1]);

                              Please help.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by WHICKED, Today, 12:56 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by Felix Reichert, Today, 02:12 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Felix Reichert  
                              Started by Tim-c, Today, 02:10 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Tim-c
                              by Tim-c
                               
                              Started by cre8able, Today, 01:16 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post cre8able  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              3 responses
                              49 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X