Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate POC value

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

    Calculate POC value

    Hi how could I be able to get the current candle POC and the 5th previous Candle POC?

    I mean, which code should I use to get the candle POC. I've used the code:

    Code:
    double currentPOC = barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]);
    double fifthPOC = barsType.Volumes[4].GetTotalVolumeForPrice(Close[4]);​
    ​​

    But I get that barsType everytime is NULL.

    Thanks in advance

    #2
    Hello speedytrade02,

    Thanks for your post.

    The POC is not currently exposed from the Order Flow indicators so that would not be something another script can detect.

    You can find a description of how you may calculate the POC yourself in the following link: https://ninjatrader.com/support/foru...79#post1112679
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks for your response Brandon.

      I've already tryied to use this method this way:

      Code:
              
      protected override void OnBarUpdate(){
          NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
          if (barsType == null)
              return;
          double currentPOC = barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]);
          double fifthPOC = barsType.Volumes[4].GetTotalVolumeForPrice(Close[4]);
      }
      ​
      But I'm getting no value returned because barsType is always NULL, so it doesn't returns anything.

      Comment


        #4
        Hello speedytrade02,

        Thanks for your notes.

        Is the Volumetric series the primary DataSeries on the chart that you are adding the script to?

        If not, you would need to call AddVolumetric() to add a volumetric bars series to your script and then call the code below in OnBarUpdate(). This is noted in the sample code on the Order Flow Volumetric help guide page linked in post # 2.

        AddVolumetric(): https://ninjatrader.com/support/help...volumetric.htm

        NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

        Further, you should make sure to check if (Bars == null) return; in your script as seen in the Order Flow Volumetric Bars sample code in the help guide.

        I have attached a simple example script to this post for your to view. See the attached screenshot showing the script works as expected when applied to a Volumetric data series chart.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Thanks so much for the example Brandon.

          And What if I wanted to plot the indicator on 1 min chart, but still using the volumetric series? I've took a look at the link you provided about AddVolumetric(), but there's any way of not specifying the instrumentName? because I want to use the indicator on many diferent instruments.

          Here I provide my code for a better understanding.

          Note: dvc (uses vwap on 1 min chart) and dpc (uses volumetric for the POC)

          Code:
          else if (State == State.Configure)
          {
              AddDataSeries(Data.BarsPeriodType.Tick, 1);
          }
          else if (State == State.DataLoaded)
          {
                  // Instantiate the indicator
                  vwap = OrderFlowVWAP(VWAPResolution.Tick, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3);
          }
          protected override void OnBarUpdate()
          {
              try{
          
                  NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
          
                  if (barsType == null)
                      return;
          
                  if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot)
                      return;
                  if (BarsInProgress == 1){
                      // We have to update the secondary tick series of the cached indicator using Tick Resolution to make sure the values we get in BarsInProgress == 0 are in sync
                      vwap.Update(OrderFlowVWAP(BarsArray[0], VWAPResolution.Tick, BarsArray[0].TradingHours, VWAPStandardDeviations.Three, 1, 2, 3).BarsArray[1].Count - 1, 1);
                  }
          
                  double result;
                  // Check the selected calculation type
                  if (CalculationTypeSelection == CalculationType.DPC){
                      double currentPOC = barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]);
                      double fifthPOC = barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[4]);
                      result = dpcCalculations(currentPOC, fifthPOC);
                  }
          
                  else{
                      result = dvcCalculations();
                  }
          
                  Value[0] = result;
              }
          
              catch (Exception e){
          
                  Print("FALLITOOOOOO --> " + e);
              }
          }​
          Thanks again

          Comment


            #6
            Hello speedytrade02,

            Thanks for your notes.

            The AddVolumetric() method does allow you to specify the instrument name of the instrument that you want to add a volumetric series for.

            See the 'Syntax' section of the AddVolumetric() help guide documentation.

            AddVolumetric(string instrumentName, Data.BarsPeriodType baseBarsPeriodType, int baseBarsPeriodTypeValue, Data.VolumetricDeltaType deltaType, int tickPerLevel)

            The sample code on the AddVolumetric() help guide documentation demonstrates adding a 1 minute Order Flow Volumetric Bars object for the ES 03-18 contract.

            AddVolumetric(): https://ninjatrader.com/support/help...=addvolumetric

            From the sample code section of the Order Flow Volumetric Bars help guide page:

            "//...if you would want to add a Volumetric series to a script, you could call AddVolumetric() in State.Configure and then for example use
            // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as
            // NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;"


            Order Flow Volumetric Bars: https://ninjatrader.com/support/help...tric_bars2.htm


            Last edited by NinjaTrader_BrandonH; 09-25-2023, 07:42 AM.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Hi Brandon,

              I've just tryied what you've said. But when I print the indicator on the 1 min chart, it still returns 0 because of the barsType == null.

              What could I be doing wrong?

              Here's my updated code:

              Code:
              namespace NinjaTrader.NinjaScript.Indicators
              {
                  public class DVC : Indicator
                  {
                      private OrderFlowVWAP vwap;
              
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                 = @"DxC VOLATILITY INDICATOR V2 (DPC or DVC)";
                              Calculate                                   = Calculate.OnBarClose;
                              BarsRequiredToPlot                          = 6;
                              IsOverlay                                   = false;
                              DisplayInDataBox                            = true;
                              DrawOnPricePanel                            = true;
                              DrawHorizontalGridLines                     = true;
                              DrawVerticalGridLines                       = true;
                              PaintPriceMarkers                           = true;
                              ScaleJustification                          = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                              IsSuspendedWhileInactive                    = true;
                          }
                          else if (State == State.Configure)
                          {
                              AddDataSeries(Data.BarsPeriodType.Tick, 1);
                              AddVolumetric("YM SEP23", BarsPeriodType.Minute, 1, VolumetricDeltaType.BidAsk, 1);
                          }
              
                          else if (State == State.DataLoaded)
                          {
                                // Instantiate the indicator
                                vwap = OrderFlowVWAP(VWAPResolution.Tick, TradingHours.String2TradingHours("CME US Index Futures RTH"), VWAPStandardDeviations.Three, 1, 2, 3);
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
              
                          if (barsType == null)
                              return;
              
                          if (CurrentBars[0] < BarsRequiredToPlot || CurrentBars[1] < BarsRequiredToPlot)
                              return;
                          if (BarsInProgress == 1){
                              // We have to update the secondary tick series of the cached indicator using Tick Resolution to make sure the values we get in BarsInProgress == 0 are in sync
                              vwap.Update(OrderFlowVWAP(BarsArray[0], VWAPResolution.Tick, BarsArray[0].TradingHours, VWAPStandardDeviations.Three, 1, 2, 3).BarsArray[1].Count - 1, 1);
                          }
              
                          double result;
              
                          // Check the selected calculation type
                          if (CalculationTypeSelection == CalculationType.DPC){
                              double currentPOC = barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[0]);
                              double fifthPOC = barsType.Volumes[CurrentBar].GetTotalVolumeForPrice(Close[4]);
                              result = dpcCalculations(currentPOC, fifthPOC);
                          }
              
                          else{
                              result = dvcCalculations();
                          }
              
                          Value[0] = result;
                      }
                  }
              }
              
              ​
              Thanks again in advance!

              Comment


                #8
                Hello speedytrade02,

                Thanks for your notes.

                I see in your script that the first added data series in your script is the 1-Tick series and your second added data series is the volumetric data series.

                The volumetric series will have a BarsArray value of 2 and you are calling BarsArray[1] in the code below which is not the volumetric series, it is the 1-Tick series.

                NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

                You would need to reference the correct BarsArray value for the volumetric series when calling the above code. In this case, BarsArray[2] would need to be used since the volumetric series is the second added series in your script.

                See this help guide page for more information about BarsArray: https://ninjatrader.com/support/help.../barsarray.htm
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                649 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                370 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                576 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X