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 pvincent, 06-23-2022, 12:53 PM
          14 responses
          238 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          382 views
          1 like
          Last Post Gavini
          by Gavini
           
          Started by oviejo, Today, 12:28 AM
          0 responses
          1 view
          0 likes
          Last Post oviejo
          by oviejo
           
          Started by pechtri, 06-22-2023, 02:31 AM
          10 responses
          125 views
          0 likes
          Last Post Leeroy_Jenkins  
          Started by judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          59 views
          0 likes
          Last Post DynamicTest  
          Working...
          X