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 sjsj2732, Yesterday, 04:31 AM
          0 responses
          36 views
          0 likes
          Last Post sjsj2732  
          Started by NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          287 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          288 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          134 views
          1 like
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          95 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Working...
          X