Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Syntax Problems
Collapse
This topic is closed.
X
X
-
skat100,
Did you click "View Code" or "Unlock Code"? To edit the code I believe you need to click on "Unlock Code". Remember that once you unlock the code on a strategy you can NOT reopen that strategy in the wizard. Other Strategies should not be effected by using the "Unlock Code" (you can still use the Wizard on Strategies that have not been unlocked).
Comment
-
Thanks for the reply. I don't understand what I am to do to correct.
Following are code lines in question. The two "Close" words which I have printed in red contained red underlines to indicate where the error is.
The actual error message for each of the two lines containing the red Close is "Cannot apply indexing with [] to an expression of type 'double'. (I typed Close as Double because I didn't find a type called currency.)
I don't know what "indexing" means and I don't know how to correct the error in each of the two places.
I'd appreciate your help. Thank you.
// Condition set 4
if (Position.MarketPosition == MarketPosition.Long
&& BarsSinceEntry() >= BSE
&& Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) < BSEp)
{
ExitLong("BSE.S", "");
}
// Condition set 5
if (Position.MarketPosition == MarketPosition.Short
&& CrossAbove(LinReg(Length), BuffetLong, 1))
{
ExitShort("CS.LRC", "");
}
// Condition set 6
if (Position.MarketPosition == MarketPosition.Short
&& BarsSinceEntry() >= BSE
&& Position.GetProfitLoss(Close[0],PerformanceUnit.Currency) < BSEp)
{
ExitShort("BSE.SS", "");
}
Comment
-
Thanks, Josh. Does the word indexing refer to the [] brackets after the word Close? I assume it means defining the number of bars back for Close. Is this correct? If so, is it proper to assign the Double type to Close? If I change the type to Currency or to int, perhaps that will solve the error problem. Should I try that?
This strategy produces a huge number of trades which I will have to whittle down but I don't think that is causing the error message.
Comment
-
More questions
When I compile, I get this message:
"Enabling “Debug Mode” should only be used by advanced programmers that intend to debug their Ninja Script in Visual Studio.
"Compiling Ninja Script objects with this mode enabled will result in runtime performance penalty.
"Please make sure you disable this mode once you are complete with your debugging and recompile your Ninja Script objects."
How do I make sure I am not in Debug Mode?
Comment
-
Syntax Errors
Following is a portion of my code. In the bold red lines in Condition Set 4 and in Condition Set 6, the compiler has indicated Error CS0021, marking the word Close in red.
// Condition set 4
if (Position.MarketPosition == MarketPosition.Long
&& BarsSinceEntry() >= BSE
&& Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) < BSEp)
{
ExitLong("BSE.S", "");
}
// Condition set 6
if (Position.MarketPosition == MarketPosition.Short
&& BarsSinceEntry() >= BSE
&& Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) < BSEp)
{
ExitShort("BSE.SS", "");
}
The text explaining Error CS0021 is as follows:
“This is a common error when calling indicator 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.”
Erroneous Sample Code – SMA is an indicator and requires parameter arguments:
Double value = SMA[0] ;
Resolution Sample Code – SMA properly called:
Double value = SMA(14)[0]
I don’t see how to insert () after the indicator name. I can’t correct the code directly. Any attempt to change the code jumps me back to the graphic where I can only access the choices presented that do not include the ability to insert ().
I’d appreciate it if you would tell me how to make this correction.
Thank you for your help.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
629 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
362 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
564 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment