Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical Plot on Volumetric Indicator

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

    Historical Plot on Volumetric Indicator

    Hi,

    I've a custom indicator and was wondering if there's a possibility to do a historical plot on a Volumetric Bar Indicator? The indicator plots real time, but not historically?

    else if (State == State.Configure)

    {

    AddVolumetric(Instrument.FullName, BarsPeriodType.Minute, 1440, VolumetricDeltaType.BidAsk, 1);

    }

    protected override void OnBarUpdate()

    {

    if (Bars == null)

    return;



    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;



    if (barsType == null)

    return;


    #2
    Hello AgriTrdr,

    The Volumetric bar type is a bar type and is not an indicator.

    If you are adding a volumetric series this would become BarsArray[1] and BarsInProgress 1.

    Code:
    if (BarsInProgress == 1 && BarsArray[1] == null)
    return;
    
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType1 = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    
    if (barsType1 == null)
    return;
    
    try
    {
    Print("=========================================== ==============================");
    Print("Bar: " + CurrentBar);
    Print(Time: " + Time[0]);
    Print("Total Volume: " + barsType.Volumes[CurrentBar].TotalVolume);
    }
    catch{}
    }


    Yes, volumetric bars load historically if you have historical tick data.

    Try loading a volumetric chart by itself.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much for your suggestion! That worked.

      So not the next question is that I would like to include this indicator into my strategy. Since it requires historical tick data to work as an indicator, do I need to enable historical tick data on the chart as the strategy? I would like to avoid that if possible because of the amount of cpu usage.

      Comment


        #4
        Hello AgriTrdr,

        The historical tick data is available from your connected provider. If its available, its available to all scripts and windows.

        The host strategy has to make all of the same AddVolumetric() calls as this hosted indicator.

        From the help guide:
        "Should your script be the host for other scripts that are creating indicators and series dependent resources in State.DataLoaded, please make sure that the host is doing the same AddDataSeries() calls as those hosted scripts would. For further reference, please also review the 2nd example below and the 'Adding additional Bars Objects to NinjaScript' section in Multi-Time Frame & Instruments"
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Yes I have added the AddVolumetric() to the script because it's in the indicator.

          Another question is I want to build the logic of the indicator into the strategy. I've mostly everything figured out besides the bars to load in OnBarUpdate().. here's what I've below. The output that I'm receiving in the output window is 2 timeframes, one for the current timeframe and one for the session end at 4:00pm even though it's not 4:00pm. I've attached the screenshot.

          protected override void OnBarUpdate()

          {

          // if (BarsInProgress != 0)

          // return;



          if (CurrentBars[0] < 60)

          return;



          if (BarsInProgress == 1 && BarsArray[1] == null)

          return;




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




          if (barsType1 == null)

          return;
          Attached Files

          Comment


            #6
            Hello AgriTrdr,

            There is no print in the code you have suggested..

            What are you printing that is printing 4:00 PM?

            Is this the primary series? What is this?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Yes, so there's 2 data series. The print is on the primary data series, and the volumetric bar is on the secondary data series.

              Comment


                #8
                Hello AgriTrdr,

                Provide the lines of code you want assistance with. Or export a reduced sample script.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Please see the reduced script below. The area that I need assistance with is in red.

                  protected override void OnBarUpdate()

                  {

                  if (CurrentBars[0] < 60 || BarsInProgress == 1 && BarsArray[1] == null)

                  return;




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




                  if (barsType1 == null)

                  return;





                  try

                  {

                  // Volumetric Bar Indicator

                  }

                  catch{}



                  // Reset the tradeCounter value at the first tick of the first bar of each session.

                  if (Bars.IsFirstBarOfSession && IsFirstTickOfBar)

                  {

                  // Logic

                  }



                  if ((Times[0][0].TimeOfDay >= StartTradingTime.TimeOfDay) && (Times[0][0].TimeOfDay <= EndTradingTime.TimeOfDay))

                  {

                  // Long and Short Logic

                  }



                  if (Position.MarketPosition == MarketPosition.Long)

                  {

                  // Scale out and Exit Logic



                  total = var11 + var14;

                  if (total == 2)

                  {

                  ScaleLong();

                  Print(Time[0] + "|" + "LONG SCALE-OUT");

                  }



                  total = var12 + var15 + var18;

                  if (total == 3)

                  {

                  ScaleLong2();

                  Print(Time[0] + "|" + "LONG SCALE-OUT2");

                  }



                  total = var16 + var18 + var19;

                  if (total == 3)

                  {

                  ExitAllLong();

                  Print(Time[0] + "|" + "EXIT ALL LONG");

                  }



                  total = var13 + var17 + var20;

                  if (total == 3)

                  {

                  ExitAllLong();

                  Print(Time[0] + "|" + "EXIT ALL LONG");

                  }

                  }



                  if (Position.MarketPosition == MarketPosition.Short)

                  {

                  // Short Scale out and Exit Logic



                  total = var21 + var24;

                  if (total == 2)

                  {

                  ScaleShort();

                  Print(Time[0] + "|" + "SHORT SCALE-OUT");

                  }



                  total = var22 + var25 + var28;

                  if (total == 3)

                  {

                  ScaleShort2();

                  Print(Time[0] + "|" + "SHORT SCALE-OUT2");

                  }



                  total = var26 + var28 + var29;

                  if (total == 3)

                  {

                  ExitAllShort();

                  Print(Time[0] + "|" + "EXIT ALL SHORT");

                  }



                  total = var23 + var27 + var30;

                  if (total == 3)

                  {

                  ExitAllShort();

                  Print(Time[0] + "|" + "EXIT ALL SHORT");

                  }

                  }

                  }

                  Comment


                    #10
                    Hello AgriTrdr,

                    if (CurrentBars[0] < 60 || BarsInProgress == 1 && BarsArray[1] == null)

                    I think you want

                    if (CurrentBars[0] < 60 || (BarsInProgress == 1 && BarsArray[1] == null ))


                    That said, if your primary bar series is volumetric and you are trying to get values from it, that would be BarsArray[0] and BarsInProgress 0.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for your response. For some reason, it's still plotting the timestamp on any condition at 4:00pm even though it's not 4:00pm. I'll be more than happy to email you the complete script. What's the best way to send it to you directly?

                      Comment


                        #12
                        Hello AgriTrdr,

                        It is best for us to assist with each other through reduced examples, as we may not be able to decipher a full script or debug the script on our end.

                        It can also help for other users of the forum to be able to reference small examples so they can learn from the experience. So we would like to encourage sharing reduced examples here.

                        That said, if you would like to email us on a scripting item, you may reach us at scriptingsupport [at] ninjatrader [dot] com.

                        To get to your question on the timestamp that is printed: Keep in mind that Time[0] represents the the timestamp of the bar that is currently processing. Times[0][0] will be the primary bar timestamp, and Times[1][0] will be the timestamp of the first added data series. If you print BarsInProgress along side your print for Time[0], you may see which data series Time[0] will be referring to.

                        Could you clarify the exact print that is giving you the unexpected timestamp? Please also include "BarsInProgress" with that print so we can confirm which data series Time[0] is representing. If you also include Times[0][0] and Times[1][0] in your prints, that can add further confirmation on what the timestamp is.

                        Comment


                          #13
                          NinjaTrader_Jim Yes that was the issue with the secondary data series and it took care of the problem.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Yesterday, 05:17 AM
                          0 responses
                          62 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          134 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          75 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          45 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          50 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X