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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    49 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    69 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    36 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    96 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    59 views
    0 likes
    Last Post PaulMohn  
    Working...
    X