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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    92 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    122 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X