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

Problem with plotting brush colors based on indicator value

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

    Problem with plotting brush colors based on indicator value

    Not sure what I doing wrong but I am trying to plot different colors based on indicator value being > 0 or < 0. It will only plot red and not green no matter what the value is with the below logic:

    protected override void OnBarUpdate()

    {
    if (Value[0] > 0)

    {
    Plots[0].Brush = Brushes.Green;
    Plots[0].Width = 20;
    }

    if (Value[0] < 0)
    {
    Plots[0].Brush = Brushes.Red;
    Plots[0].Width = 20;
    }
    }

    Update:

    When running the indicator live the color changes work but they change the colors of all the previous days as well. So when the value is greater than 0 it turns all the bars green on the current day as well as all the bars on the previous days. When the value is less than 0 it turns all the bars red on the current day as well as the previous days. I would like for all bars that are greater than 0 to be green and stay green and all the bars that are less than 0 to turn red and stay red.
    Last edited by EminiMES; 03-31-2022, 09:30 AM.

    #2
    Hi EminiMES, thanks for writing in. The PlotBrushes[][] is the proper array to use to change individual plot colors. I attached an example for reference.

    Kind regards,
    -ChrisL
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Tried the following and it didn't work... guess there is more to it than that.

      protected override void OnBarUpdate()

      {
      if (Value[0] > 0)

      {
      PlotBrushes[0][0] = Brushes.Green;
      }

      if (Value[0] < 0)
      {
      PlotBrushes[0][0] = Brushes.Red;}
      }
      }

      Comment


        #4
        Hi Emini, Please use Print(); to print out the value of the Plot, and to see if the condition is becoming true:

        Code:
        Print(Value[0]);
        if (Value[0] > 0)
        
        {
            Print("Setting Plot to Green");
            PlotBrushes[0][0] = Brushes.Green;
        }
        
        if (Value[0] < 0)
        {
            Print("Setting Plot to Red");
            PlotBrushes[0][0] = Brushes.Red;}
        }
        }
        Also, make sure you are performing this code after Value[0] is set, and check the Log tab of the Control Center for any errors.

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          It's working fine now... not sure what the issue was but I logged out and logged back in and it worked using PlotBrushes.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          9 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          20 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X