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 01-21-2010, 10:02 AM   #1
kaywai
Senior Member
 
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
Default newbie question

for example i have this script,

if (Open[0] < Low[period])
{
upwardbreak = Low[period];
}

if the condition is not met, how do i say "do nothing"? Or I don't have to write a script for "do nothing"?

The reason why I ask this is because the script is suppose to "do something" when a certain condition is met. If you look at the attached chart, that green square, to me, is some number plucked from somewhere! BTW script is also attached.
Attached Images
File Type: gif chart.png (25.6 KB, 5 views)
Attached Files
File Type: zip kyopen.zip (1.6 KB, 4 views)
Last edited by kaywai; 01-21-2010 at 10:21 AM.
kaywai is offline  
Reply With Quote
Old 01-21-2010, 10:23 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

kaywai, depends on your script and logic - if you do not change the value (condition not met) it would keep the assigned one.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-21-2010, 10:24 AM   #3
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

To do nothing, just don't code anything and it won't do anything.

What your code is doing right now is setting variables to highs and lows. Then you are drawing the dots on every single bar. Even if no new high/low is set, it is still drawing the dots with the old values. You need to place them inside the if-statement if you don't want them to draw.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-21-2010, 10:35 AM   #4
kaywai
Senior Member
 
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
Default

Josh, I understand what you are saying but not quite sure how to achieve that end? Would you mind helping? The script is attached to the initial posting
kaywai is offline  
Reply With Quote
Old 01-21-2010, 10:42 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Like this -
Code:
 
 
if ((Open[0] < Low[period]))
   {
    upwardbreak = Low[period];
    DrawSquare("tag1", true, 0, upwardbreak, Color.Green);
   }
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-21-2010, 10:58 AM   #6
kaywai
Senior Member
 
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
Default

Bertrand, It certainly looks a lot better now!

Question I have now is how do i give instructions so that if either of the conditions is not met, the square doesn't print at all?
kaywai is offline  
Reply With Quote
Old 01-21-2010, 11:54 AM   #7
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

Use bool variables. Only when both bool variables are true do you draw the dot, otherwise don't draw.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-22-2010, 06:24 AM   #8
kaywai
Senior Member
 
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
Default

guys, would you mind giving some pointers on how to begin with bool? tried something along the lines of:-

private BoolSeries myBoolSeries;
myBoolSeries = new BoolSeries(this);

myBoolSeries.Set(Open[0] < Low[period] ? true : false);

got stuck after that...
kaywai is offline  
Reply With Quote
Old 01-22-2010, 07:14 AM   #9
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

kaywai,

No need to go to a BoolSeries. A simple bool would do.

In Variables region you can go:
Code:
private bool condition1 = false;
private bool condition2 = false;
Then in your OnBarUpdate():
Code:
if (Open[0] < Low[period])
{
     condition1 = true;
}
else
{
     condition1 = false;
}

if (some other condition)
{
     condition2 = true;
}
else
{
     condition2 = false;
}

if (condition1 == true && condition2 == true)
{
     DrawSquare(...);
     DrawSquare(the other square...);
}
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-22-2010, 08:04 AM   #10
kaywai
Senior Member
 
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
Default

Thank you very much for your help Josh!
kaywai 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
Newbie question blarouche Indicator Development 1 04-08-2009 04:43 AM
newbie question j4068 Miscellaneous Support 1 03-08-2009 07:04 PM
newbie question machiavelly Charting 5 01-02-2009 06:10 AM
probably a newbie question cornelius Strategy Development 4 11-14-2008 11:02 AM
Newbie Question mwbokc Miscellaneous Support 1 02-15-2005 02:29 AM


All times are GMT -6. The time now is 03:55 PM.