CS0021

View as Markdown

The following CS0021 error code information is provided within the context of NinjaScript. The examples provided are only a subset of potential problems that this error code may reflect. In any case, the examples below provide a reference of coding flaw possibilities.

Error Code Explanation

This is a common error when calling indicators methods. It occurs when an indicator is called without its required parameter arguments before accessing an indexed value.

To fix this error you will need to first pass to the indicator method all the necessary parameter arguments. You can do this with () after the indicator name. Please note that you will still need to pass an empty parameter argument list even if your indicator requires no arguments.

Error Description #1

Cannot apply indexing with [] to an expression of type ‘method group’

Examples

Example #1

Erroneous Sample Code - SMA is an indicator and requires parameter arguments

1double value = SMA[0];

Resolution Sample Code - SMA() properly called

1double value = SMA(14)[0];

Example #2

Erroneous Sample Code - EMA is an indicator and requires parameter arguments

1double maDelta = EMA[0] - EMA[1];

Resolution Sample Code - SMA() properly called with an overload method (one of several variations)

1double maDelta = EMA(High, 14)[0] - EMA(High, 14)[1];