![]() |
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 |
|
Junior Member
Join Date: Dec 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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;
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2008
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
I will have someone reply to you on Monday. Thank you for your patience.
Ben
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |