Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

array operator [] vs value[]

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

    array operator [] vs value[]

    Hello,

    accessing an indicator like SMA I can access the value ofd the currentbar as

    double d= INDICATOR(parameter).Value[currentbar]

    using the Value property


    how is the array [] operator handled in NT?

    is the above always the same as:

    double d=INDICATOR(parameter)[currentbar]


    Best regards
    Andreas

    #2
    Originally posted by zweistein View Post
    is the above always the same as:

    double d=INDICATOR(parameter)[currentbar]
    The syntax is rather like this:
    double d=INDICATOR(parameter).PropertyArray[currentbar]

    INDICATOR(parameter) is a method-call for a method of the Indicator class (base classs of your custom indicator). This method returns a pointer to the related instance of your custom indicator.
    .PropertyArray[] is the "getter" of an array property which belongs to the public interface of your custom indicator.

    Regards
    Ralph

    Comment


      #3
      Hi Ralph,

      I tried this:


      double a=SMA(3)[0];
      double b=SMA(3).Value[0];
      //double c=SMA(3).PropertyArray[0];

      Print(
      "a="+a.ToString()+"b="+b.ToString());

      but .PropertyArray[0] gives a compile error and was therefore commented.

      In my example a equals b, therfore the array operator [] is mapped to the getter .Value[0]

      For code elegance I would like to use the array operator [] ,

      but is it always mapped to .Value[] ?

      What happens if the indicator defines a Property Value.
      Will the array operator [] still map to the derived class or will it point to the base class definition of Value?

      Please explain the .PropertyArray further.

      Thank you
      Andreas

      Comment


        #4
        Hi Andreas,

        with .PropertyArray I ment an arbitrary name for a poroperty (i.e. myColor). Therefore I misunderstood your question and my previous answer was rubbish anyway.

        The Indicator base class creates and stores instances of your custom indicator based on the signature of all members of the public properties. To correct myself: therefore the brackets [] do not have to do anything with the public properties of the custom indicator.

        So, the syntax INDICATOR(parameter)[index] looks to me like an indexed class (indexer is the key word here). It is just a guess, but perhaps NT stores the indicator's values (for the bars of a series) by means of indexed classes. I couldn't find and explanation for .Value[index]. You confirmed that it compiles and works properly, so it looks like a synonym for an indexer access. If that's true, I could imagine that it still would be possible to use "Value" as a property name. I am personally wouldn't do that, because "value" is also used as a key word for the set-accessor of a property.

        Regards
        Ralph

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        683 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        386 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        584 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        585 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X