Announcement

Collapse
No announcement yet.

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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          566 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X