Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem plotting OrderFlowVWAP

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

    Problem plotting OrderFlowVWAP

    error CS0029 on line 69 failing to plot OrderFlowVWAP. attached code shows simple plot of a sma. added coding of exact same form for OrderFlowVWAP. but can not convert type double to OrderFlowVWAP. What am i doing wrong? thanks!
    Attached Files

    #2
    Hello Kicks.Spin,
    Use below:
    Code:
    OrderFlowVWAP1 = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.None, 1, 2, 3).VWAP;
    You should define Series in State.DataLoaded, hope it helps!

    Comment


      #3
      thanks for your response s.kinra. the attached code does define series in State.DataLoaded. It is commented out because it generates error. i can not export ninjascript add on with a compile error. so that why commented out. how to get a compile/plot? thanks

      Comment


        #4
        Hello Kicks.Spin, thanks for writing in.

        Your code is not implementing the OrderFlowVWAP properly. Please see the example on the documentation page:

        https://ninjatrader.com/support/help...flow_vwap2.htm

        First, a 1 tick series needs to be added in State.Configure.

        Code:
        [B]else if (State == State.Configure)[/B]
        
        [B]{[/B]
        
        [B] AddDataSeries(Data.BarsPeriodType.Tick, 1);[/B]
        
        [B]}[/B]
        After this, initialize the object in State.DataLoaded:

        Code:
        OrderFlowVWAP1 = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.None, 1, 2, 3);
        Then you can access the values in OnBarUpdate e.g.

        Code:
        protected override void OnBarUpdate()
        {
        
        if (CurrentBars[0] < 0)
        return;
        
        if(BarsInProgress == 0)
        {
            Print(OrderFlowVWAP1.VWAP[0]);
        }
        
        if(BarsInProgress == 1)
        {
            OrderFlowVWAP1.Update();
        }
        
        }
        Please let me know if I can assist any further.

        Comment


          #5
          hello kinra: this compiles with prints to troubleshoot. can you look? there is some sort of conflict with .VWAP type and OrderFlowVWAP. regards,
          Attached Files

          Comment


            #6
            Hello Kicks.Spin,
            You need to print as below:
            Print(string.Format("{0} CurrentBar | {1} OrderFlowVWAP1, {2} HMA", CurrentBar, OrderFlowVWAP1.VWAP[0], HMA1[0]));
            Also include the changes as suggested by Chris i.e. add tick series & use barsinprogress to update vwap as shown by Chris.

            Comment


              #7
              i tried to implement your code suggestion but failed to compile. my goal is to write an indicator (not a strategy) that plots VWAP for the RTH during RTH otherwise plot VWAP for a custom night session i created. line 87 compile error in properties section. "indicator already has a definition for VWAPSessions" what am i doing wrong to fail to plot? thanks. code below.
              //This namespace holds Indicators in this folder and is required. Do not change it.
              namespace NinjaTrader.NinjaScript.Indicators
              {
              public class OrderFlowVWAPSessions : Indicator
              {
              OrderFlowVWAP VWAPValueRTH;
              OrderFlowVWAP VWAPValueON;
              OrderFlowVWAP VWAPSessions;

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"RTH and ON VWAP calcs";
              Name = "OrderFlowVWAPSessions";
              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.Orange, "VWAPSessions");
              }
              else if (State == State.Configure)
              {
              AddDataSeries(Data.BarsPeriodType.Tick, 1);
              }

              else if (State == State.DataLoaded)
              {
              VWAPValueRTH = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.None, 1, 2, 3);
              VWAPVAlueON = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures Evening Session (MLR)"), VWAPStandardDeviations.None, 1, 2, 3);
              }
              }

              protected override void OnBarUpdate()
              {
              if (CurrentBars[0] < 0)
              return;

              if(BarsInProgress == 0)
              {
              Print(VWAPValueRTH.VWAP[0]);
              Print(VWAPValueON.VWAP[0]);
              if ((Times[0][0].TimeOfDay >= new TimeSpan(8, 30, 0)) && (Times[0][0].TimeOfDay <= new TimeSpan(15, 15, 0)))
              {VWAPSessions = VWAPValueRTH;}
              else{VWAPSessions = VWAPValueON;}
              }

              if(BarsInProgress == 1)
              {
              VWAPSessions.Update();
              }
              }
              #region Properties

              [Browsable(false)]
              [XmlIgnore]
              public Series<double> VWAPSessions
              {
              get { return Values[0]; }
              }
              #endregion

              Comment


                #8
                Hello,
                My observations:
                1. Before OnStateChange, you should initiate as "private OrderFlowVWAP VWAPValueRTH;" for all similarly.
                2. In DataLoaded, define all 3 initiated above, you are defining only 2 currently.
                3. For Plots you should not use any names used above, currently you are using VWAPSessions which you initiated already so the error.
                Fix it & see if it works for you. Hope it helps!

                Comment


                  #9
                  id did that. still not working. why are three initiations required? there are only two VWAP sessions which need initiation. we just need to select one and plot that. so i did this and failed. can i go back to the well one more time here. i am missing some fundamental i think

                  public class OrderFlowVWAPSessions : Indicator
                  {
                  private OrderFlowVWAP VWAPValueRTH;
                  private OrderFlowVWAP VWAPValueON;

                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"RTH and ON VWAP calcs";
                  Name = "OrderFlowVWAPSessions";
                  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.Orange, "VWAPSessions");
                  }
                  else if (State == State.Configure)
                  {
                  AddDataSeries(Data.BarsPeriodType.Tick, 1);
                  }

                  else if (State == State.DataLoaded)
                  {
                  VWAPValueRTH = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.None, 1, 2, 3);
                  VWAPVAlueON = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures Evening Session (MLR)"), VWAPStandardDeviations.None, 1, 2, 3);
                  VWAPChoice = OrderFlowVWAP(VWAPResolution.Standard, TradingHours.String2TradingHours("CME US Index Futures Evening Session (MLR)"), VWAPStandardDeviations.None, 1, 2, 3);


                  }
                  }

                  protected override void OnBarUpdate()
                  {
                  if (CurrentBars[0] < 0)
                  return;

                  if(BarsInProgress == 0)
                  {
                  Print(VWAPValueRTH.VWAP[0]);
                  Print(VWAPValueON.VWAP[0]);
                  if ((Times[0][0].TimeOfDay >= new TimeSpan(8, 30, 0)) && (Times[0][0].TimeOfDay <= new TimeSpan(15, 15, 0)))
                  {VWAPSessions = VWAPValueRTH;}
                  else{VWAPSessions = VWAPValueON;}
                  }

                  if(BarsInProgress == 1)
                  {
                  VWAPSessions.Update();
                  }
                  }
                  #region Properties

                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> VWAPSessions
                  {
                  get { return Values[0]; }
                  }

                  Comment


                    #10
                    You must understand what you're doing.
                    Earlier you initiated 3 & defined 2, now you initiated 2 & defined 3, how do you think it will work?
                    I am not suggesting anything, I just asked you to correct it. You need to know if you need 2 or 3.
                    Please note, if you are initializing 3 you must define 3 & if you are initializing 2 you must define 2.

                    Comment


                      #11
                      Nailed it. I get it now. Thanks for your patience and direction. Sleeping helps too. lol The attached code calcs OrderFlow VWAP for RTH and night sessions separately. It uses a custom overnight trading hours session i defined. idk how to upload that. Anyone is welcome to use this, but you pry get a compile error until a custom trading session defined. Let me know if you have any pointers on the logic. Regards
                      Attached Files

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, 03-13-2026, 05:17 AM
                      0 responses
                      86 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      151 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      79 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      52 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      59 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X