Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Color bar based on volume condition

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

    Color bar based on volume condition

    Hello,

    I am trying to color each bar based on a simple condition: if the volume of that bar is greater of the previous bar volume.
    I have tried this:

    Code:
    protected override void OnBarUpdate()
    {
    if (Volume[0] > Volume[1])
       BarBrush = Brushes.Goldenrod;
    }
    it compiles but when I add it to the chart it does nothing. What am I missing?

    #2
    I noticed in the log section this error: Error on calling OnBarUpdate method on bar 0

    So I added a fix:

    Code:
    protected override void OnBarUpdate()
    {
    if( CurrentBar < 1 )
      return;
    
    if (Volume[0] > Volume[1])
      BarBrush = Brushes.Goldenrod;
    }
    Now the indicator works. Please let me know if there is a better way to avoid this error.

    Comment


      #3
      Hello Adrift,

      Calling Volume[1] with an index of 1 bar ago when CurrentBar is 0, will cause an index error. There isn't 1 bar ago on the first bar. CurrentBar would need to be equal to or greater than 1 so that there would be a bar 1 bar ago.

      Below is a link to a forum post on indexing errors.
      Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X