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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      598 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      557 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      555 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X