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 09-28-2009, 12:20 PM   #1
DaveS
Senior Member
 
Join Date: Feb 2006
Location: London U.K.
Posts: 152
Thanks: 3
Thanked 2 times in 2 posts
Default Logic Problem?

Can anyone tell me why this does not work? It never prints an arrow.

protected override void OnBarUpdate()
{
if (Low[0] < Low[1]) // Problem is in this line.
{
DrawArrowUp("Up" + CurrentBar, false, 0, Low[0] - (1 * TickSize), Color.Blue);
}
}

I know the problem is in the 'if' statement, if I change it to

if (Close[0] >= Median[0])

It prints arrows correctly.

Thanks
Dave
DaveS is offline  
Reply With Quote
Old 09-28-2009, 12:26 PM   #2
noevictorian
Member
 
Join Date: Aug 2009
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

Dave,

I was about to post a near identical question to the board when I saw your post from today. I'm having the same problem with simple logic. My code is as follows:

double myInteger = Close[1];
if (Close[0] > myInteger)
{
Plot0.Set(100);
} else {
Plot0.Set(0);
}

My code is actually a modified thing that I did during troubleshooting but you'll see that the problem boils down to the same thing...

Comparing basic OHLC data between two bars when one references a historic value.

Close[0] > Close[1]

Just like you... if I do something like Close[0] = Open[0], it works. But once I reference a [1] or [2], it breaks.

This seems so fundamental that I feel like an idiot for not figuring it out. But I'm glad to know that I'm not alone and there's clearly some trick we're both missing.
noevictorian is offline  
Reply With Quote
Old 09-28-2009, 12:37 PM   #3
DaveS
Senior Member
 
Join Date: Feb 2006
Location: London U.K.
Posts: 152
Thanks: 3
Thanked 2 times in 2 posts
Default

I went through the same agony. It seemed so simple that I thought I must be doing something stupid.

Hopefuly someone will have the answer.
DaveS is offline  
Reply With Quote
Old 09-28-2009, 01:08 PM   #4
noevictorian
Member
 
Join Date: Aug 2009
Posts: 38
Thanks: 0
Thanked 0 times in 0 posts
Default

In case any NinjaTrader admin reads this thread and wants to chime in... here's the simplest demonstration of the problem I could think of:

If you follow Lesson 1 from the NinjaScript help tutorials you create an indicator that draws a line every time the close price = the open price. The code is this:

protected override void OnBarUpdate()
{
Plot0.Set(Open[0] == Close[0] ? 1 : 0);
}

If all you do is change it to this:

protected override void OnBarUpdate()
{
Plot0.Set(Open[0] == Close[1] ? 1 : 0);
}

The whole thing fails to plot. No errors come up. And it compiles successfully... just is a blank plot on the chart.
noevictorian is offline  
Reply With Quote
Old 09-28-2009, 01:13 PM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Errors do come up with those codes you guys are using. You will see it in the Control Center log. Please see this tip on what needs to be done: http://www.ninjatrader-support2.com/...ead.php?t=3170
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-28-2009, 01:21 PM   #6
DaveS
Senior Member
 
Join Date: Feb 2006
Location: London U.K.
Posts: 152
Thanks: 3
Thanked 2 times in 2 posts
Default

So there you go Noevictorian, we WERE doing something wrong.

Thanks very much Josh, that fixed it.
DaveS 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
Logic Error texasnomad Strategy Development 2 07-23-2009 05:07 AM
Help with Exception Logic shawnj General Programming 6 12-08-2008 06:21 AM
simple order management logic problem Willl Strategy Development 3 03-27-2008 11:13 AM
Order Pending Logic Oli Automated Trading 12 04-02-2007 03:13 AM
Order logic and OnBarUpdate MrBaffalo Strategy Development 2 01-29-2007 04:54 AM


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