Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to fix Class memer declaration expected error

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

    how to fix Class memer declaration expected error

    How to fix class member declaration expected

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MyStrategy : Strategy
    {
    public MyStrategy()

    public override string DisplayName
    {
    get { return "My strategy name v3"; } -> error on this line
    }​
    private double currentPnl;

    #2
    Hello tkaboris,

    Was this strategy created using the new strategy wizard in the NinjaScript Editor? I suspect that the line "public MyStrategy()" is part of what is throwing the error. I do see that it looks like you are trying to override the DisplayName of the strategy. There is a snippet demonstration that on the help guide page here:


    Following that snippet and including elements from the code you have shared, the following does compile on my end:

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class MyStrategy : Strategy
        {
            private double currentPnL;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name                                        = "MyStrategy";
                }
            }
    
            public override string DisplayName
            {
                get { return "My strategy name v3"; }
            }
    
            protected override void OnBarUpdate()
            {
                Print(DisplayName);
            }
        }
    }​
    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X