![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Senior Member
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
|
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 at 08:27 PM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,660
Thanks: 113
Thanked 187 times in 182 posts
|
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 |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
|
VariableSumNS.jpg
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. |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
|
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? |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,660
Thanks: 113
Thanked 187 times in 182 posts
|
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 |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
|
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...
|
|
|
|
|
|
#7 | |
|
Senior Member
|
Quote:
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) ... |
|
|
|
|
|
The following user says thank you to koganam for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can I define the "Time to flatten" for the "Exit on Close" in the NinjaScript? | dleekk | General Programming | 5 | 11-09-2009 12:46 AM |
| define a session | binwang2 | General Programming | 8 | 08-23-2009 06:52 PM |
| Change cell color in Market Analyzer based on variable that is not used for display | tomtom | Indicator Development | 1 | 07-13-2009 03:52 PM |
| how to define 'the future' ? | Thomas79 | General Programming | 8 | 05-11-2009 07:21 AM |
| Is it possible to define sub category or user define category for parameters | theperm | Strategy Development | 7 | 05-16-2007 08:48 AM |