Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

VWAP Std Dev parameters

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

    #16
    Hello EthanHunt, thanks for your post.

    The method call has invalid parameters. See the examples on this page for reference:


    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #17
      Hi NinjaTrader Support! Hope you can help me please (new user trying to ramp up).
      The documentation (https://ninjatrader.com/support/help...flow_vwap2.htm) is great for printing and I can successfully print the VWAP & Standard Deviations (therefore should be able to use it/modify it within a strategy) but I need to plot the VWAP on my strategy chart. Many of the links in this and other forum threads are now broken so not sure if I'm missing something for how to plot this? Please could you outline how VWAP can be plotted on a chart within a strategy? Copying below what I have so far but this produces a compile error of "Cannot implicitly convert type 'double' to 'NinjaTrader.NinjaScript.Indicators.OrderFlowVWAP' ".

      Code:
      private OrderFlowVWAP _myVWAP;
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults) //State where default values are set.
      {
      ...redacted...
      }
      else if (State == State.DataLoaded) 
      {
      _myVWAP = OrderFlowVWAP(VWAPResolution.Tick, Bars.TradingHours, VWAPStandardDeviations.Three, 1, 2, 3).VWAP[0];
      _myVWAP.Plots[0].Brush = Brushes.Red;
      AddChartIndicator(_myVWAP);
      }
      protected override void OnBarUpdate()
      {
      double VWAPStdDevUp1 = OrderFlowVWAP(VWAPResolution.Tick, Bars.TradingHours, VWAPStandardDeviations.Three, 1, 2, 3).StdDev1Upper[0];
      Print("The current VWAP with a tick resolution on " + Bars.TradingHours.ToString() + " is " + VWAPStdDevUp1.ToString()); //THIS PART WORKS
      }
      For transaparency, I am trying to plot VWAP + 1std Deviation higher/lower, then create a ATR 'band' above and below the StdDev (and plot these all on a chart). Attaching an image of how it looks like on tradingview (orange lines are the adjusted 'band' off VWAP 1std variations)

      Many thanks in advance
      Attached Files

      Comment


        #18
        Hi Chainsaw, thanks for posting.

        The initialization of the VWAP is referencing an index:

        _myVWAP = OrderFlowVWAP(VWAPResolution.Tick, Bars.TradingHours, VWAPStandardDeviations.Three, 1, 2, 3).VWAP[0]

        it should be:

        _myVWAP = OrderFlowVWAP(VWAPResolution.Tick, Bars.TradingHours, VWAPStandardDeviations.Three, 1, 2, 3);

        Then you can use _myVWAP within OnBarUpdate e.g.


        double VWAPStdDevUp1 = _myVWAP.StdDev1Upper[0]; //since you already set up the VWAP object in State.DataLoaded

        Also, make sure you add the 1 tick series like the example does.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #19
          Thank you Chris, this is helpful. It may be that I need to go away and learn more (rather than requesting support) as I'm only half way there at the moment and it might be something not clicking for me...

          If I'm understanding it correctly, the following placed within State.DataLoaded is loading in a series, and adds it to the chart successfully (albeit with all 3 std dev sets on the chart, I haven't figured out how to reduce to just one set yet).

          Code:
          _myVWAP = OrderFlowVWAP(VWAPResolution.Tick, Bars.TradingHours, VWAPStandardDeviations.Three, 1, 2, 3);
          AddChartIndicator(_myVWAP);
          However when I try to manipulate part of the series and plot it to the chart, I'm failing. For example, lets say that I want to find the mid-point between the VWAP & 1 StdDev Upper Bound, and then plot this new value to the chart (this is just an example to illustrate, I know I could set std dev to 0.5 to achieve the same result - it's the process I'm trying to understand). Within OnBarUpdate I can use the following to get the correct output (aka I can print this to the Ninjascript Output window and it's correct):

          Code:
          double VWAPStdDevUp1 = _myVWAP.StdDev1Upper[0];
          double newVWAP = _myVWAP.VWAP[0];
          double NewVWAPMidBand = ((VWAPStdDevUp1 - newVWAP)/2)+newVWAP;
          Print(string.Format("Time: {0}, NewVWAP: {1}, OldVWAP: {2}, VWAP UPPER: {3}", Time[0], NewVWAPMidBand, newVWAP, VWAPStdDevUp1));
          But what I don't know is how to THEN get same data (NewVWAPMidBand) onto the chart as a plotted line. I assume that I need to perhaps create a new series (https://ninjatrader.com/support/help...8/?seriest.htm) but not sure yet. If you have any high level direction please kindly do let me know.

          Thanks again

          ChainsawDR

          Comment


            #20
            Hi Chainsaw, thanks for your reply.

            You must call AddPlot() and set the proper Values[][] array to plot extra data. E.g. if you add a single plot: AddPlot(Brushes.Blue, "MyPlot"); you can plot out any value in OnBarUpdate:

            Values[0][0] = ((VWAPStdDevUp1 - newVWAP)/2)+newVWAP;

            A basic example of plotting can be found in most indicators, including the SMA indicator.

            Kind regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #21
              Thank you Chris (for both your answers and your patience)! My query is now resolved but posting some additional info in case anyone else comes up against this in future and got confused as I had....

              In the example you provided, I was initially struggling to connect how the Values section ties back to the "MyPlot" section. I've been coding within a strategy with lots of different sections to it, so I wasn't sure how the system would know that 'Values' relates to 'MyPlot'. Or put another way, if it was written in the following way...

              Code:
              AddPlot(Brushes.Blue, "MyPlot");
              MyPlot[0][0] = ((VWAPStdDevUp1 - newVWAP)/2)+newVWAP;
              ... then I'd understand how they connect. Within the AddPlot() documentation you shared it has the following example of 3 add plots that makes it clear that its the indexing of values that ties back to AddPlot (thanks for writing good documentation!):

              Code:
              protected override void OnStateChange()
              {
                if (State == State.SetDefaults)
                {
                  Name = "Examples Indicator";
              
                  // Add three plots and associated Series<double> objects
                  AddPlot(Brushes.Blue, "PlotA");     // Defines the plot for Values[0]
                  AddPlot(Brushes.Red, "PlotB");     // Defines the plot for Values[1]
                  AddPlot(Brushes.Green, "PlotC");   // Defines the plot for Values[2]
                }
              }
              protected override void OnBarUpdate()
              {
                Values[0][0] = Median[0];   // Blue "Plot A"
                Values[1][0] = Low[0];       // Red "Plot B"
                Values[2][0] = High[0];     // Green "Plot C"
              So to summarize the solution

              Code:
              //the new variable is declared at the top under public class
              private double NewVWAPMidBand;
              
              //AddPLot is added within SetDefaults
              AddPlot(Brushes.Orange, "NewVWAPMidBand");
              
              //then finally the values added within OnBarUpdate
              Values[0][0] = ((VWAPStdDevUp1 - newVWAP)/2)+newVWAP;
              Thanks again for the help!

              ChainsawDR

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by RookieTrader, Today, 09:37 AM
              3 responses
              14 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by kulwinder73, Today, 10:31 AM
              0 responses
              5 views
              0 likes
              Last Post kulwinder73  
              Started by terofs, Yesterday, 04:18 PM
              1 response
              23 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by CommonWhale, Today, 09:55 AM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Gerik, Today, 09:40 AM
              2 responses
              7 views
              0 likes
              Last Post Gerik
              by Gerik
               
              Working...
              X