CS0029

View as Markdown

The following CS0029 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 error can occur when you try to convert from one type to another type.

To fix this error, ensure that you are assigning the correct value type.

Error Description #1

Cannot implicitly convert type ‘int’ to ‘bool

1// Erroneous Sample Code - 'CurrentBar' is an integer
2if (CurrentBar)
1// Resolution Sample Code - Compares an integer with another integer
2if (CurrentBar < 1)

Error Description #2

Cannot implicitly convert type ‘double’ to ‘bool

1// Erroneous Sample Code – Close[0] returns A **double** value
2if (Close[0])
1// Resolution Sample Code – Compares a double with another double
2if (Close[0] > Close[1])

Error Description #3

Cannot implicitly convert type ‘NinjaTrader.NinjaScript.Indicators.SMA’ to ‘double

1// Erroneous Sample Code - Incorrect since assigning an indicator to a variable of double type
2double myValue = SMA(20);
1// Resolution Sample Code - Correct expression since we are accessing the current bar's value of the SMA indicator
2double myValue = SMA(20)[0];