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 SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      36 views
      0 likes
      Last Post SalmaTrader  
      Started by CarlTrading, 07-05-2026, 01:16 PM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 06-17-2026, 10:32 AM
      0 responses
      14 views
      0 likes
      Last Post CaptainJack  
      Started by kinfxhk, 06-17-2026, 04:15 AM
      0 responses
      19 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 06-17-2026, 04:06 AM
      0 responses
      22 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X