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

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.

        Chris L.NinjaTrader Customer Service

        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 rocketman7, Today, 01:00 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post rocketman7  
                      Started by wzgy0920, 04-20-2024, 06:09 PM
                      2 responses
                      27 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, 02-22-2024, 01:11 AM
                      5 responses
                      32 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, 04-23-2024, 09:53 PM
                      2 responses
                      74 views
                      0 likes
                      Last Post wzgy0920  
                      Started by Kensonprib, 04-28-2021, 10:11 AM
                      5 responses
                      193 views
                      0 likes
                      Last Post Hasadafa  
                      Working...
                      X