Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

conditional ?:

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

    conditional ?:

    why wont this line of code compile?

    Z == X <> 0? Y/X*100 : 0;

    this wont compile...


    it says, invalid expression
    on the 0 it says expected ;


    it suppose to set Z to be Y/X *100 if X <> 0, if false then set Z to be 0.

    help help help,

    #2
    Hello James377,

    == is for comparing equality.
    = is for assigning values.
    != not equal to.

    You should use:
    z = x != 0 ? y / x * 100: 0;

    This tutorial walks you through setting up this type of statement if you're looking for more examples.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      for another line I am getting an error message saying doesnt exist in current context,

      but i have declared this variable as a public double? it should exist everywhere shouldnt it?

      Comment


        #4
        No, you will want to declare variables as private and accessed within the script. Public variable declarations are only used when:
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          that worked perfectly thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          156 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          74 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          125 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          79 views
          0 likes
          Last Post PaulMohn  
          Working...
          X