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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    333 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    211 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    196 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    287 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    242 views
    0 likes
    Last Post CarlTrading  
    Working...
    X