Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninja Script compile error

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

    Ninja Script compile error

    Hello: I have this line of code in my script and getting below compile error. Please advise what is needed to fix this error. Thanks.

    // Calculate daily PnL
    dailyPnL += Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);

    // my logic here to go long
    {
    EnterLongLimit(Close[0] + (TickSize * 2), "Long", takeProfit, stopLoss);
    }
    // my logic to go short
    {
    EnterShortLimit(Close[0] - (TickSize * 2), "Short", takeProfit, stopLoss);

    ================================================== ===============================
    here are the compile error.

    Click image for larger version

Name:	image.png
Views:	120
Size:	105.4 KB
ID:	1321247​​​
    Attached Files

    #2
    Hello mtamaku,

    Thank you for your post.

    GetProfitLoss() is not a valid NinjaScript method in NinjaTrader 8. Instead, use GetUnrealizedProfitLoss().



    Your EnterLongLimit and EnterShortLimit calls are not using the correct syntax. I suggest reviewing the Help Guide pages for the correct syntax.





    Please let us know if you have any further questions.

    Comment


      #3
      Thank you. This helped and I fixed the error and have a clean compile of my strategy.

      But I do not see this strategy in the list when I tried to apply this strategy from the chart trader or from the strategy tab in main window using right click and clicking on strategy menu option.

      Please advise how to add this strategy to a chart.

      Comment


        #4
        If your strategies are not showing up in the list of available strategies then that suggests there is an issue with the strategies themselves. Specifically, there is likely an error in OnStateChange().

        Keep in mind that while it may compile successfully, the compiler cannot check "run time" logic errors, which can only occur when you run (or load) the strategy.

        A good first step here is to check the "Log" tab of the Ninjatrader Control center and look for any errors related to the strategies as if there is a run time error is would show in the log tab.

        If there are no log errors, check (in the Ninjascript editor open each strategy) to see if the strategies have the same name (IE you made a copy of the strategy and made your changes but unintentionally left the name the same as an existing one).

        In general, you want the filename of the strategy (this is what Ninjascript editor uses to open the script) to be the same as the public class name and most importantly that inside OnStateChange and within State.SetDefaults, the Name = field (This is what the drop-down or strategy selector uses) shows the same name as the public class name.​

        Comment


          #5
          Hi, here was Addseries statement in onstatechange(_) section was the root cause which I found in log when I try to add the strategy.
          After removing , I am able to see my new strategy and I can select it.
          Thanks for help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          556 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X