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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    46 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    67 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    35 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    95 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