Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error CS 1525 with if...else if...else

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

    Error CS 1525 with if...else if...else

    This is the code:

    Code:
                if(Math.Log(tr[x])=0)
                {
                d = Math.Abs( 0 - Math.Log(tr[x+1]));
                }
                else if (Math.Log(tr[x+1])=0);
                {
                d = Math.Abs(Math.Log(tr[x]));
                }
                else
                {
                d = Math.Abs(Math.Log(tr[x])- Math.Log(tr[x+1]));
                }
    Compiling gives " Invalid expression term 'else' " with CS-1525 in line containing last else.
    It gives " ; expected " in that line and " Statement expected " in previous line.

    I'm very lost.

    Thanks in advance,

    Sergio

    #2
    Please try the below Sergio :

    Code:
     if(Math.Log(tr[x])=0)
                {
                d = Math.Abs( 0 - Math.Log(tr[x+1]));
                }
                else if (Math.Log(tr[x+1])=0)
                {
                d = Math.Abs(Math.Log(tr[x]));
                }
                else
                {
                d = Math.Abs(Math.Log(tr[x])- Math.Log(tr[x+1]));
                }

    Comment


      #3
      Didn't work :-(

      Comment


        #4
        What errors are you now getting if you compile your scirpt? Could you perhaps post the full script so we could give it a run and see?

        Thanks,

        Comment


          #5
          I get the same error messages.

          If I replace the total branch with

          Code:
          d = Math.Abs(Math.Log(tr[x])- Math.Log(tr[x+1]));
          it compiles without errors.

          I need to avoid "0" in the Math.Log argument with the code exposed in starting message.

          Comment


            #6
            Hi sercava,

            You have assignments in your if statements. Please try the following which test for equality with == instead.


            Code:
             if(Math.Log(tr[x])==0)
                        {
                        d = Math.Abs( 0 - Math.Log(tr[x+1]));
                        }
                        else if (Math.Log(tr[x+1])==0)
                        {
                        d = Math.Abs(Math.Log(tr[x]));
                        }
                        else
                        {
                        d = Math.Abs(Math.Log(tr[x])- Math.Log(tr[x+1]));
                        }
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Finally worked! Thanks.

              Have fun!

              Sergio

              Comment


                #8
                Great to hear. Thanks for updating us and enjoy your weekend!
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                574 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                332 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
                553 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X