Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

'If' statements with BarColor comand

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    '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.

    #2
    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 P.NinjaTrader Customer Service

    Comment


      #3
      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, 01:53 PM.

      Comment


        #4
        Hello,

        I will have someone reply to you on Monday. Thank you for your patience.
        DenNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by toughiee, Today, 12:04 AM
        0 responses
        3 views
        0 likes
        Last Post toughiee  
        Started by vdoan20, Yesterday, 08:30 PM
        0 responses
        8 views
        0 likes
        Last Post vdoan20
        by vdoan20
         
        Started by gupagoer, Yesterday, 07:42 PM
        0 responses
        9 views
        0 likes
        Last Post gupagoer  
        Started by Holligoly, Yesterday, 05:13 PM
        2 responses
        11 views
        0 likes
        Last Post Holligoly  
        Started by Raginpower, Yesterday, 01:53 PM
        0 responses
        14 views
        0 likes
        Last Post Raginpower  
        Working...
        X