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 NullPointStrategies, Today, 05:17 AM
      0 responses
      51 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      128 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      69 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X