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

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 ageeholdings, Today, 07:43 AM
          0 responses
          3 views
          0 likes
          Last Post ageeholdings  
          Started by pibrew, Today, 06:37 AM
          0 responses
          4 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by rbeckmann05, Yesterday, 06:48 PM
          1 response
          14 views
          0 likes
          Last Post bltdavid  
          Started by llanqui, Today, 03:53 AM
          0 responses
          6 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by burtoninlondon, Today, 12:38 AM
          0 responses
          12 views
          0 likes
          Last Post burtoninlondon  
          Working...
          X