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

Array problem

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

    Array problem

    Can someone tell what is the problem with this loop :


    double[] X = newdouble[257];
    double[] Y = newdouble[257];
    for
    (int iBar=0;iBar<nBars;iBar++)
    {
    X(iBar)=iBar;
    Y(iBar)= (MAX(High,nBars-iBars)[
    0]+MIN(Low,nBars-iBars)[0])/2;
    }

    I don't understand the error message :
    "X is an "array" but is used like a "method" "

    #2
    try

    X[iBar] = iBar;

    [] is used for accessing items in a collection, () is used for methods.
    RayNinjaTrader Customer Service

    Comment


      #3
      ok

      and how do you code "^" in C# ?
      ex :
      W[iBar]=W[iBar]+Avect[jCoef]*iBar^(jCoef-
      1);

      I also have a problem with absolute value.
      Is it Abs()?

      Comment


        #4
        I don't know what "^" means? If you can tell me that, maybe I can help.

        Check out the .NET Math class.

        Math.Abs(value) etc...
        RayNinjaTrader Customer Service

        Comment


          #5
          when I use ^ in the previous statement I have the following error message :

          ^ operator cannot be applied to operands of type int or double

          Comment


            #6
            right, its not valid. What I am saying is that I don't know what "^" is supposed to do.

            For example:

            * = multiply
            / = divide
            ^ = ???
            RayNinjaTrader Customer Service

            Comment


              #7
              I give you an example:

              a^2=a*a;
              a^n=a*a*a....*a (n times)

              Comment


                #8
                - please consult the MS docs to properly understand the C# operators
                - you likely are looking for the Math.Pow() function. Please consult the MS docs for details

                Comment


                  #9
                  msdn is where you look for generic dot net C# methods documentation.

                  The methods of the Math class are listed here:
                  Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.


                  As NTDierk pointed out, the number raised to a power method is probably what you want:

                  Comment


                    #10
                    thank you for your help. I think I'm starting to understand C# a little bit more thanks to you.
                    I finally succeed in coding my indicator.
                    compilation is ok but when I try to use my indicator I got the following error message :

                    Error on calling the OnBarUpdatemethod() method for indicator 'BAMcenter' on bar 100 : index is out of array's bound.

                    I already use a code to ensure there would be no problem with index and I can't find the problem.
                    Here is the script :

                    Attached Files

                    Comment


                      #11
                      It means on the 100th bar from left to right you are accessing an array where the index value passed in is greater than the number of elements in the array.

                      Here is something that may be of value - http://www.ninjatrader-support.com/v...ead.php?t=3170
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        I already use these kind of loop to ensure there would be no problems with index. I think the problem lies elsewhere.
                        Indeed, I just tried to translate a free public VBA code published by a french trader.
                        I followed every step concensciously but I didn't understand the end of the code :

                        For iBar=0 to nBars-1
                        W(iBar)=0;
                        For jCoef=1 to Degree+1
                        W(iBar)=W(iBar)+Avect(jCoef)*iBar^(jCoef-1)
                        Next jCoef
                        .SetIndicatorValue W(iBar),1,(nBars-1-iBar)
                        .SetIndicatorValue W(iBar)*smthg,2,(nBars-1-iBar)
                        Next iBar

                        I underlined the part of the code I did not understand and could not translate.
                        the numbers 1 and 2 are probably used for the plotting but the (nBars-1-iBars) does not make any sense to me.

                        Comment


                          #13
                          kuroro13,

                          We are not experts on VBA, but you would need to recheck your loop since you are running into the index out of bound issue.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by yertle, Yesterday, 08:38 AM
                          7 responses
                          28 views
                          0 likes
                          Last Post yertle
                          by yertle
                           
                          Started by bmartz, 03-12-2024, 06:12 AM
                          2 responses
                          21 views
                          0 likes
                          Last Post bmartz
                          by bmartz
                           
                          Started by funk10101, Today, 12:02 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post funk10101  
                          Started by gravdigaz6, Yesterday, 11:40 PM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by MarianApalaghiei, Yesterday, 10:49 PM
                          3 responses
                          10 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Working...
                          X