Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reset(able) VWAP

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

    Reset(able) VWAP

    Hi,
    I found the following code for a VWAP indicator.

    I want to reset this, say every hour, instead of day, any idea how to go about it?

    ========================
    amespace NinjaTrader.NinjaScript.Indicators
    {
    public class VWAP8 : Indicator
    {
    double iCumVolume = 0;
    double iCumTypicalVolume = 0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Volume Weighted Average Price";
    Name = "VWAP8";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    AddPlot(Brushes.Black, "PlotVWAP");
    }
    }

    protected override void OnBarUpdate()
    {
    if (Bars.IsFirstBarOfSession)
    {
    iCumVolume = VOL()[0];
    iCumTypicalVolume = VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3);
    }
    else
    {
    iCumVolume = iCumVolume + VOL()[0];
    iCumTypicalVolume = iCumTypicalVolume + (VOL()[0] * ((High[0] + Low[0] + Close[0]) / 3));
    }

    PlotVWAP[0] = (iCumTypicalVolume / iCumVolume);
    }
    =====================


    Thanks

    #2
    Hello SuperDriveGuy,

    The condition 'if (Bars.IsFirstBarOfSession)' is the condition that is triggering on the first bar of a new session.

    You could instead have this condition trigger if the Time[0].Minute is 0 (meaning its the end of an hour).

    Or you could save the bar time to a variable when the condition is true, and then in the condition ensure the time of the current bar is 1 hour greater than the saved value. (Time[0].AddHours(1) > savedTimeValue)
    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
    596 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
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    554 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X