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 argusthome, 03-08-2026, 10:06 AM
      0 responses
      116 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      61 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      40 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      44 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      82 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X