Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Partial Class issue

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

    Partial Class issue

    I've created some sample code to demonstrate an issue I have. I've created a sample Indicator with one class and one dictionary. I want to keep a function in a partial class that accepts as a parameter, a Dictionary<string,SymbolInfo>. However, it does not seem to want to let me pass the Dictionary to the method in the partial class. Here is the code:

    Indicator Code:
    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class WontCompile : Indicator
        {    
            public Dictionary<string, SymbolInfo> SymbolsInfo = new Dictionary<string, SymbolInfo>();            
    
            public class SymbolInfo{
                public double Last { get; set; }        
            }
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionBuySellVolume;
                    Name                    = "WontCompile";
                    Calculate                = Calculate.OnEachTick;
                    DrawOnPricePanel        = false;
                    MaximumBarsLookBack        = MaximumBarsLookBack.Infinite;
                    IsOverlay                = false;
                    DisplayInDataBox        = true;
                }
                if (State == State.Configure){                
                    ClearOutputWindow();
                }
            }
        }
    }
    And, I've created a partial class with a single method in it so that I can use the method in more than one indicator like this:

    Partial Class Code:
    Code:
    public partial class Indicator
    {
        public void MyMethod(Dictionary <string, SymbolInfo> dict){
            Print(dict.Count);
        }
     }
    However, it's not letting me compile with that Dictionary<string,SymbolInfo> in the Partial class. Here is the error I get:
    Code:
    The type or namespace name 'SymbolInfo' could not be found (are you missing a using directive or an assembly reference?)
    Do I need to share the SymbolInfo class with the partial class? I didn't think that was the case but perhaps I am misunderstanding. As always, thanks,

    #2
    Hello swcooke,

    The SymbolInfo class would need to be visible to both the partial class and the indicator class, it looks like you have the SymbolInfo inside the indicators class so you are adding another step to finding the SymbolInfo type. Your partial class would need to be specific and use the fully qualified name to the type or a better easy solution would be to just place the SymbolInfo class above your partial classes file so both your indicator and partial class have access.

    Here is an example which is all in one file, if you have a separate file for the partial class it would be the same concept and structure. Both the partial class and the SymbolInfo are in the toplevel namespace NinjaTrader.NinjaScript.Indicators where the indicator is at so all are visible.


    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class Test : Indicator
        {
            public Dictionary<string, SymbolInfo> SymbolsInfo = new Dictionary<string, SymbolInfo>();
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"Enter the description for your new custom Indicator here.";
                    Name = "Test";
                    Calculate = Calculate.OnBarClose;
                    IsOverlay = false;
                    DisplayInDataBox = true;
                    DrawOnPricePanel = true;
                    DrawHorizontalGridLines = true;
                    DrawVerticalGridLines = true;
                    PaintPriceMarkers = true;
                    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive = true;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
            }
        }
    
        public class SymbolInfo
        {
            public double Last { get; set; }
        }
    
        public partial class Indicator
        {
            public void MyMethod(Dictionary<string, SymbolInfo> dict)
            {
                Print(dict.Count);
            }
        }
    }

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    670 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    379 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    111 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    575 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    582 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X