Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 xiinteractive, 04-09-2024, 08:08 AM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Johnny Santiago, 10-11-2019, 09:21 AM
        95 responses
        6,193 views
        0 likes
        Last Post xiinteractive  
        Started by Irukandji, Today, 09:34 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by RubenCazorla, Today, 09:07 AM
        1 response
        6 views
        0 likes
        Last Post RubenCazorla  
        Started by TraderBCL, Today, 04:38 AM
        3 responses
        26 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X