NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

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.

Reply
 
Thread Tools Display Modes
Old 05-07-2012, 08:25 PM   #1
billr
Senior Member
 
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
Default 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 at 08:27 PM.
billr is offline  
Reply With Quote
Old 05-07-2012, 10:53 PM   #2
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,640
Thanks: 111
Thanked 185 times in 180 posts
Default

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.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 05-08-2012, 04:46 PM   #3
billr
Senior Member
 
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
Default

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.
billr is offline  
Reply With Quote
Old 05-08-2012, 04:56 PM   #4
billr
Senior Member
 
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
Default

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?
billr is offline  
Reply With Quote
Old 05-08-2012, 07:48 PM   #5
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,640
Thanks: 111
Thanked 185 times in 180 posts
Default

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.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 05-08-2012, 08:45 PM   #6
billr
Senior Member
 
Join Date: Apr 2010
Location: San Antonio, Texas
Posts: 315
Thanks: 31
Thanked 2 times in 2 posts
Default

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...
billr is offline  
Reply With Quote
Old 05-08-2012, 09:18 PM   #7
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO, USA
Posts: 1,640
Thanks: 111
Thanked 185 times in 180 posts
Default

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 at 11:06 PM.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 05-08-2012, 10:36 PM   #8
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
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) ...
koganam is online now  
Reply With Quote
The following user says thank you to koganam for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 12:21 AM.