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 cmoran13, 04-16-2026, 01:02 PM
                0 responses
                43 views
                0 likes
                Last Post cmoran13  
                Started by PaulMohn, 04-10-2026, 11:11 AM
                0 responses
                25 views
                0 likes
                Last Post PaulMohn  
                Started by CarlTrading, 03-31-2026, 09:41 PM
                1 response
                163 views
                1 like
                Last Post NinjaTrader_ChelseaB  
                Started by CarlTrading, 04-01-2026, 02:41 AM
                0 responses
                98 views
                1 like
                Last Post CarlTrading  
                Started by CaptainJack, 03-31-2026, 11:44 PM
                0 responses
                158 views
                2 likes
                Last Post CaptainJack  
                Working...
                X