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

Bar Color

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

    Bar Color

    I wish to set bar colors using the following formula

    if(Close[0]>h1)
    BarColor=color.green;
    if(close[0]<l1)
    BarColor=color.red;

    What section do I need to include code in and what would I need to declare for the code to work.

    Thanks

    Craig

    #2
    Hi Craig,

    Logic generally goes inside the OnBarUpdate() method. You would need to declare the h1 and l1 variables. Also, Color needs to be capitalized.

    BarColor = Color.Red;
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Bar Colors 2

      I placed this code in the
      OnBarUpdate() section of code and it shows no errors.
      It does however not overide the normal Candlestick colors that are the default.
      What would I need to do to achieve this?
      {
      // Condition set 1
      if (Close[0] > High[1])
      {
      BarColor=Color.Green;
      }
      // Condition set 2
      if (Close[0] < Low[1])
      {
      BarColor=Color.Red;
      }
      }
      Thanks

      Craig

      Comment


        #4
        Its a good habit to check the Log tab since you will see an error in there when applying this indicator to a chart. Please review the content in the following link which outlines what you need to do to fix your code.

        RayNinjaTrader Customer Service

        Comment


          #5
          The following now works. Thanks for your help
          {
          if (CurrentBar < 2)
          return;
          // Condition set 1
          if (Close[0] > High[1])
          {
          BarColor=Color.Green;
          }
          // Condition set 2
          if (Close[0] < Low[1])
          {
          BarColor=Color.Red;
          }}

          I now wish to code the following. Can you please suggest ways I might approach this.
          if condition 1 is true then subsequent bars to be colored green until condition 2 is true
          if condition 2 is true then subsequent bars to be colored red until condition 1 is true

          Thanks

          Craig

          Comment


            #6
            Create a variable in the variables section of your script,

            private Color myColor = Color.Green;

            then in OnBarUpdate()

            Code:
            if (CurrentBar < 2)
                return;
             
            if (Close[0] > High[1])
                myColor = Color.Green;
            else if (Close[0] < Low[1])
                myColor = Color.Red;
             
            BarColor = myColor;
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            11 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            5 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            5 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X