Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compare Current Candle Volume with previous candle's Volume

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

    Compare Current Candle Volume with previous candle's Volume

    Just tying to modify current Ninjatrader Volume Indicator (VOL) but am having a difficult time understanding Value() and Values() along with the AddPlot line of code.

    I would just like to compare the current candle's volume with the previous candles volume to determine if the current candle's volume is greater than or less than the previous candle's volume.
    If it is greater, I would like to plot the current candle's volume in a lighter shade of green and if it is less I would like to plot the current candle's color in a different darker color.

    I am unsure how to alter (or add to) the Value[0] definition in the code to get the previous candle's volume numerical value for comparison and also how to alter the AddPlot line of code to still plot all the volume bars.

    Any assistance would be greatly appreciated. Thank you.
    Below is the Ninjatrader VOL indicator lines of code (in bold text) I am referring to:


    public class VOL : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = Custom.Resource.NinjaScriptIndicatorDescriptionVOL ;
    Name = Custom.Resource.NinjaScriptIndicatorNameVOL;
    BarsRequiredToPlot = 0;
    Calculate = Calculate.OnEachTick;
    DrawOnPricePanel = false;
    IsSuspendedWhileInactive = true;

    AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, Custom.Resource.VOLVolume);
    AddLine(Brushes.DarkGray, 0, Custom.Resource.NinjaScriptIndicatorZeroLine);
    }
    else if (State == State.Historical)
    {
    if (Calculate == Calculate.OnPriceChange)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", string.Format(Custom.Resource.NinjaScriptOnPriceCh angeError, Name), TextPosition.BottomRight);
    Log(string.Format(Custom.Resource.NinjaScriptOnPri ceChangeError, Name), LogLevel.Error);
    }
    }
    }

    protected override void OnBarUpdate()
    {
    Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
    }
    }​

    #2
    Hi obiwan_cashobi,

    To access the value of the previous candle, specifically access the value at the candle 1 bar ago, you can use Values[0][1] or Value[1].
    To colorize the Plot, you can use PlotBrushes.

    Please refer to the code below:

    Code:
    protected override void OnBarUpdate() {
      Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
    
      double vol0 = Value[0];
    
      // use Value[1] to access the value at 1 bar ago.
      double vol1 = (CurrentBar == 0) ? 0 : Value[1];
    
      // use PlotBrushes to colorize the Plot.
      PlotBrushes[0][0] = (vol0 > vol1) ? Brushes.LightGreen : Brushes.DarkGreen;
    }

    For more information about the Addplot() function, the Values and Value objects, you can access the following links to learn more:




    Regard,
    William
    ninZa
    NinjaTrader Ecosystem Vendor - ninZa.co

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    656 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    371 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    579 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X