Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modify VolumeUpDown Indicator

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

    Modify VolumeUpDown Indicator

    I'm trying to modify the standard VolumeUpDown indicator to include flat bars (Close = Open). My goal is to have 3 volume bar colors (Close > Open is Blue, Close < Open is Red and Close = Open is Gray). With my below modifications it will only show Blue and Gray bars but no Red bars. Not sure what I'm doing wrong.

    Modified code:


    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class VolumeCustom : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionVolumeUpDown;
    Name = "VolumeCustom";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    IsSuspendedWhileInactive = true;
    DrawOnPricePanel = false;

    AddPlot(new Stroke(Brushes.Blue, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeUp);
    AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VolumeDown);
    AddPlot(new Stroke(Brushes.Gray, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VOLVolume);
    AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
    }
    else if (State == State.Historical)
    {
    if (Calculate == Calculate.OnPriceChange)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnPriceChangeError, Name), TextPosition.BottomRight);
    Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnPriceChangeError, Name), LogLevel.Error);
    }
    }
    }

    protected override void OnBarUpdate()
    {
    if (Close[0] > Open[0])
    {
    Values[0][0] = Volume[0];
    Values[1].Reset();
    }
    else if (Close[0] < Open[0])
    {
    Values[1][0] = Volume[0];
    Values[1].Reset();
    }
    else
    {
    Values[0].Reset();
    Values[2][0] = Volume[0];
    }
    }
    }
    }

    #2
    Hello,

    Thank you for the post.

    I believe you would need to Reset both the Plots you do not wish to see on that bar. It looks like you are currently only resetting the Blue plot or Values[0].

    Could you try adding Values[1].Reset(); as well?

    Additionally, the price being exactly equal may not occur due to how double numbers are stored in memory. You may instead need to check equality using math rather than this being an else case. You can find more on this topic in the following post: http://ninjatrader.com/support/forum...ead.php?t=3929

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    587 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    341 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
    555 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X