Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarColor does not work from OnMarketData()?

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

    BarColor does not work from OnMarketData()?

    Hi,

    I am trying to write an indicator using OnMarketData() method and have it color bars based on the bar values. However, it seems like BarColor is being completely ignored in this case.

    I can see that bar values go from positive to negative but the bar color remains the same - the one specified in indicator properties in UI. What am I doing wrong? Should I be using a different Plot constructor?

    Code:
    public class TugOfWar : Indicator {
    ...
    private static readonly Color BULL_BAR_COLOR = Color.FromKnownColor(KnownColor.DodgerBlue);
    private static readonly Color BEAR_BAR_COLOR = Color.FromKnownColor(KnownColor.Firebrick);
    
    protected override void Initialize()
    {
        Plot p = new Plot(BULL_BAR_COLOR, PlotStyle.Bar, "BarWinners");
        Add(p);
        p.Pen.Width = 5;
    
        Overlay                = false;
        CalculateOnBarClose = false;
    }
    
    protected override void OnBarUpdate() {} // currently not used - empty
    
    protected override void OnMarketData(MarketDataEventArgs md) {
        ...
        int diff = volAtAsk - volAtBid;
        BarColor = (diff >= 0 ? BULL_BAR_COLOR : BEAR_BAR_COLOR);
        BarWinners.Set(diff);
    }

    #2
    Hello alexandroid,

    Thank you for your post.

    BarColor would change the color of the bars on the chart and not what is listed in the Data Series menu of the chart. Are the bars on the chart not changing colors?

    Comment


      #3
      Oh my God, yes, the bars on the chart do! I was so focused on watching my indicator bars that I completely missed that.

      I've tried adding DrawOnPricePanel = false to Initialize() method but it still does not help.

      How can I achieve different colored bars for my indicator?

      Comment


        #4
        alexandroid,

        Thank you for your response.

        You would use PlotColors, you can find a reference sample at the following link: http://ninjatrader.com/support/forum...ead.php?t=3227

        Comment


          #5
          Thank you very much! Using PlotColors[0][0] = BULL_BAR_COLOR; works!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          175 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          331 views
          0 likes
          Last Post CaptainJack  
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          253 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          356 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          183 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Working...
          X