Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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]));
                }
    BertrandNinjaTrader Customer Service

    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,
        BertrandNinjaTrader Customer Service

        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 ScottWalsh, 04-16-2024, 04:29 PM
                6 responses
                27 views
                0 likes
                Last Post ScottWalsh  
                Started by frankthearm, Today, 09:08 AM
                10 responses
                35 views
                0 likes
                Last Post frankthearm  
                Started by GwFutures1988, Today, 02:48 PM
                0 responses
                3 views
                0 likes
                Last Post GwFutures1988  
                Started by mmenigma, Today, 02:22 PM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by NRITV, Today, 01:15 PM
                2 responses
                9 views
                0 likes
                Last Post NRITV
                by NRITV
                 
                Working...
                X