Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error code CS02446

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Error code CS02446

    Any assistance for the following error, much appreciated - Merry xmas

    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));
    }
    }
    }
    }

    #2
    Hello Roadhouse33,

    Welcome to the NinjaTrader forums!

    Have you deleted any of the default using statements at the top of the TRAP script?

    Create a new blank strategy. Copy the using statements from the top of the new strategy to your custom TRAP strategy.

    Let me know if this does not resolve the error.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Also, you put :
      private readonly Timespan targetTime = new TimeSpan(9, 30, 0); // 9:30 AM
      ​So, I'm guessing you just need to change one or the other to make TimeSpan match Timespan.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X