NinjaScript File,Error,Code,Line,Column,
TRAP.cs,The type or namespace name 'TimeSpan' could not be found (are you missing a using directive or an assembly reference?),CS0246,8,17,
TRAP.cs,The type or namespace name 'TimeSpan' could not be found (are you missing a using directive or an assembly reference?),CS0246,8,43,
I am getting the following error for a limit order strategy script:
namespace NinjaTrader.NinjaScript.Strategies
{
public class LimitOrderLevels : Strategy
{
private double[] buyLevels;
private double[] sellLevels;
private bool ordersPlaced;
private readonly Timespan targetTime = new TimeSpan(9, 30, 0); // 9:30 AM
private double levelDistance = 10; // Distance between levels in ticks
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "LimitOrderLevels";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 1 || ordersPlaced)
return;
// Check if the current time matches the target time
if (Time[0].TimeOfDay >= targetTime)
{
PlaceLimitOrders();
ordersPlaced = true; // Ensure orders are placed only once
}
}
private void PlaceLimitOrders()
{
double marketPrice = Close[0];
// Calculate buy levels
buyLevels = new double[3];
for (int i = 0; i < 3; i++)
{
buyLevels[i] = marketPrice - (levelDistance * (i + 1)) * TickSize;
EnterLongLimit(1, buyLevels[i], "BuyLevel" + (i + 1));
}
// Calculate sell levels
sellLevels = new double[3];
for (int i = 0; i < 3; i++)
{
sellLevels[i] = marketPrice + (levelDistance * (i + 1)) * TickSize;
EnterShortLimit(1, sellLevels[i], "SellLevel" + (i + 1));
}
}
}
}

Comment