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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      87 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      128 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      65 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      117 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      67 views
      0 likes
      Last Post PaulMohn  
      Working...
      X