• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ninjascript: How do I define Variable value based on other variables?

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

    Ninjascript: How do I define Variable value based on other variables?

    I'm sure this is a basic question, but I am having trouble figuring out how to accomplish the following:

    I would like to have certain conditions set a value for Variables and then use those variables to determine an aggregate value. In this case I tried to use another Variable to define the aggregated value. For instance;

    int Variable0=0;
    int Variable1=0;
    int Variable2=0;
    int Variable3=0;
    int Variable4=0;
    int Variable5=0;
    int Variable9=0;
    {
    // Condition set 1
    if (CCI(14)[0] > 0)
    {
    Variable0 = 25;
    }

    // Condition set 2
    if (CCI(30)[0] > 0)
    {
    Variable1 = 25;
    }

    // Condition set 3
    if (CCI(40)[0] > 0)
    {
    Variable2 = 25;
    }

    // Condition set 4
    if (CCI(14)[0] < 0)
    {
    Variable3 = 25;
    }

    // Condition set 5
    if (CCI(30)[0] < 0)
    {
    Variable4 = 25;
    }

    // Condition set 6
    if (CCI(40)[0] < 0)
    {
    Variable5 = 25;

    (so far so good)

    I would now like to set Variable9==(Variable0 + Variable1)


    Variable9==(Variable0+Variable1)

    I tried several variations of what you see in Red above.

    This is where I am having a problem. I keep getting script errors
    but cant decipher how to write the code. Any help would be appreciated.

    Thanks.
    Last edited by billr; 05-07-2012, 08:27 PM.

    #2
    Hello billr,

    Thank you for your post.

    Please respond with a screenshot of the errors with the name and description fields clearly readable.

    To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CRTL + V to paste the image. Lastly, save as a jpeg file and attach to your response.

    I look forward to assisting you further.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Click image for larger version

Name:	VariableSumNS.jpg
Views:	1
Size:	233.1 KB
ID:	865249

      Attached is a screenshot as per your request. I couldn't recall the syntax I tried earlier to get more specific error messages. The current errors are 'expected' items only.

      What you see is an example that set Variables to a numeric value if a certain condition was true. What I inserted was a line "Variable9==(Variable0+Variable1+Variable2)" in an attempt to set the value of Variable9 to the sum of Variables0-2 at the close of each bar.
      I have circled in red the only language I added that triggers the errors. If I remove the circled script, it will compile.

      Hope that is clear.
      Thanks.

      Comment


        #4
        To clarify, my original question relates to my attempt to set Variable9 to a value by taking the sum of Variables0-2. Setting Variables 0,1, & 2 based on conditions worked fine. The problem was how to set a Variable (in this case Variable9) to a value that equals the sum of Variable0,1,and 2 ?

        Ultimately, I want to use Variable9 as part of a condition. e.g. if Variable9==20 then do something.

        Is trying to do this with a Variable a problem?

        Comment


          #5
          Hello billr,

          Thank you for your response.

          Please launch our remote support application from the following link, http://www.ninjatrader.com/remotesupport.
          Once launched, the application will provide you with an ID# and password. I will need these from you via email reply and will happily investigate this item in a timely manner - please also leave the remote application running, so I can connect properly.

          Please send you reply to support[at]ninjatrader[dot]com with "ATTN: Patrick" in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=49675

          I look forward to assisting you further.
          Patrick H.NinjaTrader Customer Service

          Comment


            #6
            I responded just after you wrote, but got the automated response. I assume you are gone for the day? Didn't want to continue to wait if you are already gone...

            Comment


              #7
              Hello Bill,

              Thank you for your time on the phone today.

              We were able to resolve the errors by changing the Variable9 assignment to the following line:
              Code:
              Variable9 = (Variable0 + Variable1 + Variable2);
              Please let me know if I may be of further assistance.
              Last edited by NinjaTrader_PatrickH; 05-08-2012, 11:06 PM.
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by billr View Post
                To clarify, my original question relates to my attempt to set Variable9 to a value by taking the sum of Variables0-2. Setting Variables 0,1, & 2 based on conditions worked fine. The problem was how to set a Variable (in this case Variable9) to a value that equals the sum of Variable0,1,and 2 ?

                Ultimately, I want to use Variable9 as part of a condition. e.g. if Variable9==20 then do something.

                Is trying to do this with a Variable a problem?
                A double equal sign is a comparator; to assign a value you need a single equal sign.

                Var09 = Var01 + Var02; etc assigns the sum of the right hand side Varx to Var09.

                Your if statement will need brackets to make it a correct comparison.

                if (Variable9==20) ...

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by dtl-saw, Today, 03:36 PM
                0 responses
                5 views
                0 likes
                Last Post dtl-saw
                by dtl-saw
                 
                Started by williamzz, Today, 02:04 PM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by jtrading82, Today, 01:55 PM
                3 responses
                22 views
                0 likes
                Last Post NinjaTrader_Tyler  
                Started by StevenNelson, Today, 01:00 PM
                4 responses
                19 views
                0 likes
                Last Post StevenNelson  
                Started by allinthechart, Today, 12:21 PM
                0 responses
                8 views
                0 likes
                Last Post allinthechart  
                Working...
                X