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 halgo_boulder, 04-20-2024, 08:44 AM
          2 responses
          21 views
          0 likes
          Last Post halgo_boulder  
          Started by mishhh, 05-25-2010, 08:54 AM
          19 responses
          6,189 views
          0 likes
          Last Post rene69851  
          Started by gwenael, Today, 09:29 AM
          0 responses
          5 views
          0 likes
          Last Post gwenael
          by gwenael
           
          Started by Karado58, 11-26-2012, 02:57 PM
          8 responses
          14,830 views
          0 likes
          Last Post Option Whisperer  
          Started by Option Whisperer, Today, 09:05 AM
          0 responses
          2 views
          0 likes
          Last Post Option Whisperer  
          Working...
          X