Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OrderFlowVwap doesn't reset on session when switch to calculate on each tick

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

    OrderFlowVwap doesn't reset on session when switch to calculate on each tick

    Trying to develop a strategy using OrderFlowVwap but I can't seem to get the indicator to function properly in code.

    Below is the code instantiating vwap and adding to chart as indicator.

    Code:
            private OrderFlowVWAP vwap;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    // skipped....
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }
                else if (State == State.DataLoaded) {                
                    vwap = OrderFlowVWAP(VWAPResolution.Tick, Bars.TradingHours, VWAPStandardDeviations.Three, 1, 2, 3);                
                    AddChartIndicator(vwap);
                }
            }​
    Below is the indicator plotted when calculate on each tick:

    Click image for larger version

Name:	image.png
Views:	134
Size:	99.7 KB
ID:	1257028
    ​Here is one with on bar close:
    Click image for larger version

Name:	image.png
Views:	124
Size:	130.6 KB
ID:	1257029
    Note that even the one calculating on bar close, it looks like some of the vwap calculation is missing or somehow not plotted on chart?

    Any advice is greatly appreciated.

    Thanks.
    Attached Files

    #2
    Hello yeungt2,

    In the code you have shown you did not include the required OnBarUpdate code, did you make your code exactly like the help guide example and include the OnBarUpdate portion of the sample?

    Comment


      #3
      Sorry for the delay.

      I didn't post the OnBarUpdate code because I have nothing in it. I did try playing with the example code in the help guide but I wasn't sure how that would help with achieving my objective here.

      My goal here is to instantiate and plot the order flow vwap indicator through my code, the same way as If I were to add the indicator separately through the UI.

      The example in the help guide only does 1-off access to the method, to reference the current value. Is there any other example out there that you can point me to?

      Comment


        #4
        Hello yeungt2,

        If you don't have any code in OnBarUpdate the indicator is not being utilized correctly. The help guide sample shows the base required logic to call that indicator from code. You can optionally use AddChartIndicator with that instance but you still need to have that OnBarUpdate code so it gets updated. That sample shows a print which is how to get values from the indicator in the BarsInProgress 0 condition. You don't have to actually get values from the indicator but you do need the added series and the BarsInProgress 1 logic to update the indicator like the sample shows.

        Comment


          #5
          Thanks Jesse.

          Yeah, I managed to get something working based on the help guide though I find what I did extremely inelegant. Will try to improve it over once I have better understanding of C# and the NinjaScript framework.

          Much appreciate the help.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 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
          554 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