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

Error CS0021

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

    Error CS0021

    Hi

    I am trying to do a SMA on a CCI with the periods used as an input. This code is being kicked out with a CS0021, Cannot apply indexing with [] to an expression of type 'method group' for line 46.

    I have looked the error message up but it doesn't seem to help with line 46: for (int barsAgo = 0; barsAgo < Period; barsAgo++)

    also i put brackets after CCI(0) - should there be a number instead of 0 - what is it? where do i find it from?

    sum = sum + CCI(0)[barsAgo];

    thanks

    protectedoverridevoid OnBarUpdate()
    {
    if (CurrentBar < Period) return;


    double sum = 0;
    for (int barsAgo = 0; barsAgo < Period; barsAgo++)
    {
    sum = sum + CCI(
    0)[barsAgo];
    }

    Plot0.Set(sum/Period);


    }




    #2
    Clicking on the error message brings you to the erroneous code line which you then can fix.

    Also: "SMA(CCI(<yourCCIPeriodValue>), <yourSMAPeriodValue>)" probably is what you are looking for.

    Comment


      #3
      To use CCI please see this link: http://www.ninjatrader-support.com/HelpGuideV6/CCI.html

      You can put it whatever values you want for the parameters.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        Hi there

        thanks for the replies - i got it compiled - it was another window i had open that i thought i'd cancelled.

        my first attempt at making an indicator.

        anyhow, now it's working it's not what i wanted.

        can you point me the direction of info i can use to build this:

        if CCI value for the last six periods is all positive OR all negative, sum them and then divide by 6.

        i will then apply that factor to a parameter in a strategy to give an indication of trend strength.

        (if you know of a really good, simple measure that will do the same i would love to know about it - so far I have tried ADX, Aroon and DM aren't working for me)

        thanks

        Comment


          #5
          Sure just go CCI(20)[0] > 0 && CCI(20)[1] > 0 && CCI...etc etc inside an if statement. Then add them up and divide by six. Or you can use a loop. Whatever works for you.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            cheers josh

            I have writen this code but nothing appears on the indicator when i add it to a chart,
            so i added print statements,
            but I can't get anything on the output window

            so simple one, how do I "run" the code to create values to appear on the output window? (and is this code right...while your on!)

            is there a detailed manual/bible in one place which covers the prog language?

            double sum = 2;

            if (CCI(14)[0] > 0 && CCI(14)[1]);
            sum = CCI(
            14)[0] + CCI(14)[1];

            Print (
            "pos sum " + sum + " CCI " + CCI(14)[0]);

            if (CCI(14)[0] < 0 && CCI(14)[1]);
            sum = CCI(
            14)[0] + CCI(14)[1];

            Print (
            "pos sum " + sum + " CCI " + CCI(14)[0]);

            TF.Set(sum/2
            );
            }

            Comment


              #7
              You likely experience this problem here: http://www.ninjatrader-support.com/v...ead.php?t=3170

              Comment


                #8
                Thanks.

                ok, so i added this statement

                if (CurrentBar < 2) return;

                2 because i tried it with 1 and it didn't work so i have 2 periods so i tried 2.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Today, 06:40 PM
                0 responses
                4 views
                0 likes
                Last Post algospoke  
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                7 views
                0 likes
                Last Post maybeimnotrader  
                Started by quantismo, Today, 05:13 PM
                0 responses
                6 views
                0 likes
                Last Post quantismo  
                Started by AttiM, 02-14-2024, 05:20 PM
                8 responses
                168 views
                0 likes
                Last Post jeronymite  
                Started by cre8able, Today, 04:22 PM
                0 responses
                9 views
                0 likes
                Last Post cre8able  
                Working...
                X