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

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 WHICKED, Today, 12:45 PM
          2 responses
          19 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by GussJ, 03-04-2020, 03:11 PM
          15 responses
          3,276 views
          0 likes
          Last Post xiinteractive  
          Started by Tim-c, Today, 02:10 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          5 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          51 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Working...
          X