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, 02:08 PM   #1
KLG08
Junior Member
 
Join Date: Dec 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default 'If' statements with BarColor comand

I'm not new to NJ but this is my first Posting to Forum.

The "BarColor" indicator I wrote compiles with no errors, however I'm sure I'm missing an: If - Then, or If - Else, or the correct use of {}'s or some other problem with the Syntax of C+. I have tried several combination of Syntax and spent a lot of time trying to figure this out. My code in question is underlined below. When I load the indicator, the bars don't change colors.

The description of my desired 'logic' is show above each 'Condition'

#region Variables
// Wizard generated variables
privateint fastHMA = 40; // Default setting for FastHMA
privateint slowerEMA = 20; // Default setting for SlowerEMA
.... generic code not show ... etc
protectedoverridevoid OnBarUpdate()
{
if (CurrentBar == 0)
{
// Condition 1 Plots GREEN bars if HMA & EMA are both trending UP.
if ((Rising(HMA(fastHMA))) && (Rising(EMA(slowerEMA))));
BarColor = Color.Green;
// Condition 2 Plots RED bars if HMA & EMA are both trending DOWN.
if ((Falling(HMA(fastHMA))) && (Falling(EMA(slowerEMA))));
BarColor = Color.Red;

// Condition 3 Plots PaleGreen bars if HMA is Falling & EMA is trending UP.
if ((Falling(HMA(fastHMA))) && (Rising(EMA(slowerEMA))));
BarColor = Color.PaleGreen;

// Condition 4 Plots RosyBrown bars if HMA is Rising & EMA is trending DOWN.
if ((Rising(HMA(fastHMA))) && (Falling(EMA(slowerEMA))));
BarColor = Color.RosyBrown;}

}

Thank you for your help.
KLG08 is offline  
Reply With Quote
Old 01-21-2010, 02:37 PM   #2
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

KLG08,

You should not end the if-statement line with a semicolon.

It should be like this pseudo-code:
Code:
if (condition1 && condition2 && others)
{
     action to do;
     another action to do;
}
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-23-2010, 12:39 PM   #3
KLG08
Junior Member
 
Join Date: Dec 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you Josh, couldn't see the forest or the ;;'s (trees).
Thank you for your prompt help.


It still didn't run correctly untill I changed the if (CurrentBar == 0) return; (which I didn't have underlined because I didn't know it was a problem). It worked fine when I changed it to if (CurrentBar < 1) return;
I'm not sure the significance of the difference since the current bar is the 0 bar which is <1. At any rate it works great. Just an educational question; what is the difference, i.e. <1 works but == 0 does not?
Last edited by KLG08; 01-23-2010 at 12:53 PM.
KLG08 is offline  
Reply With Quote
Old 01-24-2010, 11:46 PM   #4
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

I will have someone reply to you on Monday. Thank you for your patience.
NinjaTrader_Ben 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
Statements if/true/false skikg General Programming 2 12-09-2009 01:45 PM
Live Print statements jerimac2 Automated Trading 2 09-29-2009 10:42 AM
IF Statements bologc NinjaScript File Sharing Discussion 3 09-03-2009 08:48 AM
Setting line width statements Terrangbil General Programming 4 10-28-2008 12:13 PM
statements ignored Burga1 General Programming 8 06-30-2008 10:36 PM


All times are GMT -6. The time now is 11:54 AM.