Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Implementing VWAP into a algo strategy

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

    Implementing VWAP into a algo strategy

    Hello,

    I have purchased the lifetime warranty and trying to figure out how to code in the VWAP into either strategy builder or ninjascript editor. I cant seem to find them as an option now that I have the lifetime.

    Thoguhts?

    #2
    Hello litamm89,

    Thank you for your post.

    Although the strategy builder will not have access to the VWAP information, when coding in the NinjaScript Editor there is NinjaScript access to VWAP per the following page:


    The full source code is not available, but the values listed on that page may be accessed accordingly.

    Please let us know if we may be of further assistance.

    Comment


      #3
      Hi Emily,

      That help page for the VWAP indicates that I have to use the small full call every time? Is that correct? When trying to code the indicator in my strategy, I'm getting an error. Apparently, it doesn't work like the other indicators.

      private ATR theATR;
      private OrderFlowVWAP theVWAP;

      ​theATR = ATR(ATRPeriod);
      theVWAP = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.UseDataSeriesSettingsInstance, VWAPStandardDeviations.None, 1, 1, 1);


      That works for the ATR instance but for the VWAP instantiation, I'm getting this:

      Compiler Error CS1955: Non-invocable member 'name' cannot be used like a method.
      Only methods and delegates can be invoked. This error is generated when you try to use empty parentheses to call something other than a method or delegate.​

      ​So, to get a VWAP value, I need this for every call?
      double VWAPValue = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.UseDataSeriesSettingsInstance, VWAPStandardDeviations.None, 1, 1, 1).VWAP[0];
      instead of this
      double VWAPValue = theVWAP.VWAP[0];

      Calling the full parameter call every time would seem to be very resource intensive. What am I missing? In short, what is the proper method for using VWAP in my code?

      Thanks!
      Matt

      Comment


        #4
        Hello Matt,

        Thank you for your note.

        Are you experiencing this while coding/compiling directly in the NinjaScript Editor? If so, what version of NinjaTrader 8 are you using? The full version number may be found at Control Center > Help > About.

        I was able to create a quick test strategy with the following and the prints showed up in the NinjaScript Output window successfully with the VWAP value:

        Code:
        // declared at class level
        private OrderFlowVWAP theVWAP;
        ​
        // in OnStateChange when State is DataLoaded
        else if (State == State.DataLoaded)
        {
        theVWAP = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.UseDataSeriesSettingsInstance, VWAPStandardDeviations.None, 1, 1, 1);
        }
        
        protected override void OnBarUpdate()
        {
        double VWAPValue = theVWAP.VWAP[0];
        Print("The VWAP Value is: " + VWAPValue);
        }

        Please try following this snippet as an example and let me know if you are still experiencing the same behavior.

        Comment


          #5
          Hi Emily,

          Thank you for the quick response! Well, I should have been more specific. I'm seeing the error in Visual Studio when writing code (that is, the VS real-time interpreter, not the VS compiler).

          Click image for larger version

Name:	VWAP_instantiation.png
Views:	1424
Size:	33.9 KB
ID:	1221791

          I do not get an error when the code is compiled by the NT Editor. I just tested and I'm seeing the values just has you did in your test. So, I'm all set.

          Thanks again!
          Matt

          Comment


            #6
            Couple of things:

            When you "run this strategy" does it just print on the screen when you see the charting results?

            Also, on the Trading.Hours function how do i know what time zone it is referencing, Eastern ect.?
            Again on the Trading.Hours funtion how do I get VWAP to reset or determine the end of the day? The function looks like it only is expecting one expression for time.

            For futures the trading day is much longer, but I want to see how the results look if I start and end at the standard market hours 9:00am eastern - 4:00 pm eastern or 8-3 my time.

            Comment


              #7
              Hello RISKYBUSINEZZ,

              Thank you for your note.

              Which strategy are you referring to? The snippet I provided in post number 4 of this thread is set up to print the VWAP value to the NinjaScript Output window. The Trading Hours used in the indicator refers to a trading hours template in the platform. Trading hours templates define the time zone and range of time for the session. You may review the different templates or create your own at Control Center > Tools > Trading Hours. For more information:


              Please let us know if we may be of further assistance.

              Comment


                #8
                Okay cool! That works for your strategy analyzer too it seems?

                Comment


                  #9
                  Hello RISKYBUSINEZZ,

                  That is correct; the Strategy Analyzer has a property where you may select the desired Trading Hours for the strategy itself (the same as if you were to select the Trading Hours when running a strategy from the Strategy tab of the Control Center or for the Data Series of a chart you wish to run a strategy on), and if the strategy references an indicator with a specific Trading Hours template then the script will calculate that indicator based on the trading hours referenced in the script.

                  Please let us know if we may be of further assistance.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  72 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  143 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  76 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  47 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  51 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X