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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    54 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    25 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    17 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    24 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X