![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
|
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.
Last edited by kaywai; 01-21-2010 at 10:21 AM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
kaywai, depends on your script and logic - if you do not change the value (condition not met) it would keep the assigned one.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
|
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
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Like this -
Code:
if ((Open[0] < Low[period]))
{
upwardbreak = Low[period];
DrawSquare("tag1", true, 0, upwardbreak, Color.Green);
}
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
|
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? |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Use bool variables. Only when both bool variables are true do you draw the dot, otherwise don't draw.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
|
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... |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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; 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...);
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Sep 2009
Posts: 562
Thanks: 40
Thanked 4 times in 4 posts
|
Thank you very much for your help Josh!
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |