Inspect the exact literal
Check the flagged character, quotes, and language version before replacing syntax.
NinjaScript compiler troubleshooting
CS1056 identifies an unexpected character. If it points to the dollar prefix of an interpolated string, inspect the literal syntax and the actual compiler language version before changing the code.
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.NinjaScript;
namespace NinjaTrader.NinjaScript.Indicators
{
public class SafeStringFormatIndicator : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "SafeStringFormatIndicator";
Description = "Demonstrates safe string formatting in NinjaScript without CS1056.";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
Period = 14;
AddPlot(Brushes.DodgerBlue, "Average");
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < Period - 1)
return;
Value[0] = SMA(Period)[0];
// Avoid string interpolation that causes CS1056 in C# 5 compiler contexts:
// Print($"Bar: {CurrentBar}, Close: {Close[0]}, SMA: {Value[0]}");
// Solution 1: Use string.Format
Print(string.Format("Bar: {0}, Close: {1:F2}, SMA: {2:F2}", CurrentBar, Close[0], Value[0]));
// Solution 2: Use string concatenation
// Print("Bar: " + CurrentBar + ", Close: " + Close[0].ToString("F2"));
}
[NinjaScriptProperty]
[Range(1, 200)]
[Display(Name = "Period", GroupName = "Parameters", Order = 0)]
public int Period { get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> Average { get { return Values[0]; } }
}
}The example uses string.Format and an explicit property getter to avoid those C# 6 constructs. Compile it in the target NinjaScript Editor; compatibility with every installation is not established.
An interpolated C# string uses $"...", not single quotes. It requires C# 6 or later. In an older compilation context, replace a simple interpolation with string.Format or concatenation while preserving values, format specifiers, and culture. A dollar sign in an invalid location can cause CS1056 for other reasons; the error alone does not identify every NinjaTrader installation as C# 5.
Check quotes, escaping, and the position of the dollar sign before diagnosing a language-version mismatch. A valid interpolated string begins with a dollar sign and double quote. If that syntax is rejected by an older compiler, a formatting replacement can remove the unsupported construct.
Record the NinjaTrader build and the compiler or external editor that produced the diagnostic. A framework version does not by itself prove which C# features the compiler accepts.
For a simple debug message, replace an interpolation with string.Format using correctly ordered placeholders. Preserve alignment, numeric formats, escaped braces, null handling, and the intended culture. Do not assume every interpolation can be replaced mechanically with identical evaluation behavior.
Expression-bodied properties, null-conditional operators, and nameof also arrived with C# 6. If the actual target requires older syntax, review those constructs too. The example uses an explicit getter to remain consistent with this older-syntax demonstration.
Modern compilers can lower interpolated strings in different ways. Do not assume identical allocations or performance from the .NET version alone; avoid unnecessary formatting in a hot path and measure if it matters.
Pineify can assist source revision and check a single Indicator or Strategy against its pinned static reference profile. That profile is not your installed NinjaTrader environment.
Use F5 in NinjaScript Editor, inspect its compile-error display, and repair remaining diagnostics. The NinjaScript Output window is for runtime Print output; an empty output window is not proof of successful compilation.
Check the flagged character, quotes, and language version before replacing syntax.
Keep placeholder order, units, numeric formats, and culture consistent when changing the message.
Compile in NinjaScript Editor and inspect its error display; use the Output window separately for Print observations.
Generate, fix, and refine complete NinjaScript indicators and strategies with static checks.
Learn how to use NinjaScript Editor compilation, diagnostics, and Print statements.
Understand NinjaScript lifecycle, series indexing, and indicator creation from scratch.
Discover how to build custom NT8 indicators with plots, parameters, and lookback guards.
This guide is for educational and software development purposes. It does not constitute investment advice. Test all code in NinjaScript Editor and simulation before using it in live trading.
Generate one editable NinjaTrader 8 Indicator or Strategy source file and review static C# and supported API diagnostics.
Move a NinjaScript file through static preflight, NinjaScript Editor compilation, source-located repairs, and focused Print output.
Learn NinjaScript lifecycle, series indexing, plots, guards, compilation, and chart testing from one small Indicator.
Build an editable NT8 Indicator with AddPlot, Values, lifecycle methods, parameters, and lookback guards.
Paste your NinjaScript indicator or strategy, resolve compiler errors like CS1056, and generate clean C# code for NinjaTrader 8.
Open NinjaTrader Coding Agent