Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Basic programming question

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

    Basic programming question

    Hello, new to Ninjascript. I have a question. I am trying to paint the bars a color when 3 parts of the macd are above the zero line. (macd, avg, diff), or when two are above and one is below, etc. I use barcolor = Color.Red and I can get it to work if I only program for one of the variables. My challenge is getting the coding correct when I want all three variables (mulitple conditions in other words). I am doing something wrong. Using "and" to add multiple conditions doesnt seem to work.
    For example:
    if A > 0 and
    B > 0 and
    C < 0
    BarColor = Color. Red ;
    this doesnt seem towork. I am probably messing up with the basic coding. Help...lol.

    #2
    You would need to do something like:

    Code:
    if (MACD(12, 26, 9).Macd[0] > 0 && MACD(12, 26, 9).Avg[0] > 0 && MACD(12, 26, 0).Diff[0] > 0)
        BarColor = Color.Red;
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks Ray, but still have a problem

      Ray, you are awesome. I used the &&; however, I am still getting an error.
      "Cannot apply indexing with [] to an expression of type 'method group'

      here is my code:
      if (MACD(12,26,9).MACD[0] > 0 && MACD(12,26,9).Diff[0] > 0 && MACD(12,26,9).Avg[0] > 0)
      BarColor = Color.Red ;


      Comment


        #4
        I edited my original post. Changed the MACD[0] to Macd[0].
        RayNinjaTrader Customer Service

        Comment


          #5
          thanks, that did it...I should have caught that

          Appreciate the help, you guys are great. I should have caught that as well. But we got it..thanks a million.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X