NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 06-07-2008, 12:47 PM   #1
eswap0
Senior Member
 
Join Date: May 2008
Posts: 126
Thanks: 0
Thanked 0 times in 0 posts
Default Using variables

I am trying to check the days between two events.
If I buy, I set a variable with ToDay(Time[0]).
My problem appears when I try to use this variabe in the next context.
Please find below an extract of my code:

Code:
// Condition set 1
if (Low[0] < MIN(Low, 20)[1]
 
{
int Inday = ToDay(Time[0]);
EnterLongStop();
}
 
// Condition set 2
 
if (Position.GetProfitLoss(Open[0], PerformanceUnit.Percent) > 0
&& ToDay(Time [0])> Inday)
{
ExitLong("", "");
} 
How can I use the variable "Inday", set in the first condition, also in the second condition?
Thanks a lot!
Last edited by eswap0; 06-07-2008 at 01:28 PM.
eswap0 is offline  
Reply With Quote
Old 06-07-2008, 03:19 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Initialize the variable outside of the if statement in the Variables section. Then you should be able to access it throughout your code.
NinjaTrader_Josh is offline  
Reply With Quote
Old 06-07-2008, 05:56 PM   #3
eswap0
Senior Member
 
Join Date: May 2008
Posts: 126
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by Josh View Post
Initialize the variable outside of the if statement in the Variables section. Then you should be able to access it throughout your code.
Thank you very much: it worked!
eswap0 is offline  
Reply With Quote
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
Global variables monpere Strategy Development 1 03-10-2008 07:06 PM
Limited use of variables andy2001 General Programming 5 03-04-2008 03:47 PM
User variables Bogan7 Strategy Development 1 01-06-2008 01:07 AM
importing variables from .txt sandro Indicator Development 1 05-15-2007 06:59 AM
Plotting variables MAX Indicator Development 2 10-30-2006 10:19 PM


All times are GMT -6. The time now is 06:00 PM.