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

Cannot apply indexing with [] to an expression of type 'double'

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

    Cannot apply indexing with [] to an expression of type 'double'

    Hello, can someone advise how to resolve the error message:
    Cannot apply indexing with [] to an expression of type 'method group'
    for this code on line 5.? (The line numbers are for reference only and are not part of the actual code.)
    1. double PctChangeOL = (Open[0]-Low[0])/Open[0];
    2. oHCount = 0;
    3. for(int i = period; i > 0; i--)
    4. {
    5. if(PctChangeOL[i] > .01)
    6. oHCount++;
    7. }

    #2
    Originally posted by ScorpioTravis View Post
    Hello, can someone advise how to resolve the error message:
    Cannot apply indexing with [] to an expression of type 'method group'
    for this code on line 5.? (The line numbers are for reference only and are not part of the actual code.)
    1. double PctChangeOL = (Open[0]-Low[0])/Open[0];
    2. oHCount = 0;
    3. for(int i = period; i > 0; i--)
    4. {
    5. if(PctChangeOL[i] > .01)
    6. oHCount++;
    7. }
    Why are you appending the index "[i]" to PctChange?
    PctChange is a double, it is not an Array, or a DataSeries.

    The code sample you've shown is extremely nonsensical,
    and strikes me as incorrect, even after "[i]" is removed.

    Perhaps you first should explain what you're trying to do?

    Comment


      #3
      Ah, perhaps you mean something like this,

      Code:
      int oHCount = 0;
      for (int i = 0; i < period; i++)
      {
          double PctChangeOL = (Open[i]-Low[i])/Open[i];
          if (PctChangeOL > .01)
              oHCount++;
      }
      Note how the for loop starts at '0' and counts up,
      which means it automatically handles the most recently
      closed bar.
      Last edited by bltdavid; 05-16-2021, 10:36 AM.

      Comment


        #4
        David, thanks for your reply.

        I'm neither a programmer nor an NT script coder. I modified another counting indicator.

        The code works without the error if I use: PctChangeOL.Set((Open[0]-Low[0])/Open[0]);

        instead of: double PctChangeOL = (Open[0]-Low[0])/Open[0];

        But I don't want it to plot, I'm sending the values to the Output window.

        Comment


          #5
          Hello ScorpioTravis,

          Thanks for your post.

          It looks like in your snippet you have created PctChangeOL as a double but it also sounds like you have defined it as a DataSeries elsewhere in the script. DataSeries are used to hold values for a plot, so it sounds like that is how PctChangeOL is used.

          You can use Ctrl + F to search the script for instances of PctChangeOL to see how it is created. If you just want to have a double and print it to the output window, you could change the variable to use a different name, so you are using something like "PctChangeDouble" instead of "PctChangeOL."

          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,602 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          8 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          4 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          12 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X