Announcement

Collapse
No announcement yet.

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
                DierkNinjaTrader Customer Service

                Comment


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

                  The methods of the Math class are listed here:
                  http://msdn.microsoft.com/en-us/libr...ds(vs.71).aspx

                  As NTDierk pointed out, the number raised to a power method is probably what you want:
                  http://msdn.microsoft.com/en-us/libr...ow(VS.71).aspx

                  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 kazisl, Today, 06:41 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post kazisl
                          by kazisl
                           
                          Started by einstein, Today, 06:20 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post einstein  
                          Started by op1031, Today, 05:51 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post op1031
                          by op1031
                           
                          Started by nighttrader99, Today, 04:34 PM
                          1 response
                          9 views
                          0 likes
                          Last Post NinjaTrader_ShawnB  
                          Started by Simon Investimens, Today, 02:51 PM
                          1 response
                          15 views
                          0 likes
                          Last Post NinjaTrader_ChrisL  
                          Working...
                          X