Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error CS0246 "the type or name could not be found"

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

    Error CS0246 "the type or name could not be found"

    Hello,

    The basics of my code are:

    namespace NinjaTrader.NinjaScript.Strategies.EvanStrategies
    {
    public class fading1 : Strategy
    {
    public NinjaTrader.NinjaScript.Indicators.TrendZigZagUTG4 zig;

    else if (State == State.DataLoaded)
    {
    zig = TrendZigZagUTG4(true, spansize, 3, 10);
    }
    }
    protected override void OnBarUpdate()
    {

    Print(zig.swings.Count); --- This works fine ----------

    foreach(swing b in zig.swings) {Print(b);} --- This throws an error CS0246: The type or namespace name 'swing' could not be found (are you missing a using directive or assembly reference?)

    }





    The indicator looks like this:

    public class TrendZigZagUTG4 : Indicator
    {
    public int dir, pb1, pb2, pb3;
    public double pv1, pv2, pv3;
    private double hival, loval, price;
    private Brush plotcolor;
    private int plotwidth;
    private bool drawlines, drawdots;



    public List <swing> swings = new List<swing>();


    public class swing

    {
    public int bar { get; set; }
    public double price { get; set; }

    }


    protected override void OnStateChange()
    {



    Any ideas what's wrong with my code?

    #2
    Here is the indicator file. In my startegy I'm just trying to do the following:

    foreach(swing b in zig.swings) {Print(b);}


    But i get error CS0246: The type or namespace name 'swing' could not be found (are you missing a using directive or assembly reference?)
    Attached Files

    Comment


      #3
      Hi evanp90, thanks for your question.

      If the swing class is not available from the script you are calling the TrendZigZag from you will get a compile error. Consider defining the swing class outside of the indicator class e.g.

      Code:
          public class swing{//definintion}
      
          public class TrendZigZagUTG4 : Indicator
          { ...}
      That will make swing available to any script that belongs to NinjaScript.Indicators.

      Please let me know if I can assist any further.

      Comment

      Latest Posts

      Collapse

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