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

BarsPeriod.BasePeriodType Not Evaluating Correctly

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

    BarsPeriod.BasePeriodType Not Evaluating Correctly

    Hello,

    When I use BarsPeriod.BasePeriodType within an indicator on a Volume chart (e.g. 10000 Vol Bars of ES) it returns "Minute" instead of expected "Volume"

    For instance :
    Code:
    if (BarsPeriod.BasePeriodType == PeriodType.Volume) 
    { 
      Do Something 
    }
    As for the data provider is external TradeStation Connection using NTExternalFeed on 10000Vol Chart.

    Why does this not evaluate correctly ?

    #2
    Hello tornadoatc,

    BarsPeriod.BasePeriodType would only relevant for Kagi, LineBreak, and PointAndFigure Bars objects.



    If you are not using those type of bars objects the you will want to use BarsPeriod.Id to check for Minute, Volume, etc...

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello tornadoatc,

      BarsPeriod.BasePeriodType would only relevant for Kagi, LineBreak, and PointAndFigure Bars objects.



      If you are not using those type of bars objects the you will want to use BarsPeriod.Id to check for Minute, Volume, etc...

      Let us know if we can be of further assistance.
      Thanks JC,

      Need to read a little closer as I was on that page previously.

      But once I changed it to BarsPeriod.Id I am getting the same TickCount for each bar. Here is the simple code:
      Code:
      				if (BarsPeriod.Id != PeriodType.Volume) // Check for Volume Bars
      				{
      					if (Close[0] > Close[1])
      						Value.Set(Value[1]+ Volume[0]);
      					else if (Close[0]  < Close[1])
      						Value.Set(Value[1] - Volume[0]);
      					else
      						Value.Set(Value[1]);
      				}
      				else if (BarsPeriod.Id == PeriodType.Volume) // Check for Volume Bars
      				{
      					Print("Current Bar = " + CurrentBar + " TickCount = " + Bars.TickCount) ; 
      					if (Close[0] > Close[1])
      						Value.Set(Value[1] + Bars.TickCount);
      					else if (Close[0]  < Close[1])
      						Value.Set(Value[1] - Bars.TickCount);
      					else
      						Value.Set(Value[1]);
      				}
      Why does the Print Statement not show correct values for TickCount?

      The print statement is returning.
      Base Period type = Volume
      Current Bar = 1 TickCount = 367
      Current Bar = 2 TickCount = 367
      Current Bar = 3 TickCount = 367
      Current Bar = 4 TickCount = 367
      Current Bar = 5 TickCount = 367
      Current Bar = 6 TickCount = 367
      Current Bar = 7 TickCount = 367
      Current Bar = 8 TickCount = 367
      Current Bar = 9 TickCount = 367
      Current Bar = 10 TickCount = 367
      etc...

      Comment


        #4
        Hello tornadoatc,

        This may be due to when OnBarUpdate() is being called. Do you have Calculate on bar close set to true? If you have set it to false do you see update in the Tick Count?
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_JC View Post
          Hello tornadoatc,

          This may be due to when OnBarUpdate() is being called. Do you have Calculate on bar close set to true? If you have set it to false do you see update in the Tick Count?
          Yes, COBC = true.

          Here is code:
          Code:
          protected override void Initialize()
                          {
                                  Add(new Plot(Color.Orange, "IBDOBV"));
                                  CalculateOnBarClose = true; 
                          }
                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                                  if (CurrentBar ==1) 
                                          Print("Base Period type = " + BarsPeriod.Id) ; 
                                  
                                  if (CurrentBar == 0)
                                          Value.Set(0);
                                  else
                                  {
                                          if (BarsPeriod.Id != PeriodType.Volume) // Check for Volume Bars
                                          {
                                                  if (Close[0] > Close[1])
                                                          Value.Set(Value[1]+ Volume[0]);
                                                  else if (Close[0]  < Close[1])
                                                          Value.Set(Value[1] - Volume[0]);
                                                  else
                                                          Value.Set(Value[1]);
                                          }
                                          else if (BarsPeriod.Id == PeriodType.Volume) // Check for Volume Bars
                                          {
                                                  Print("Current Bar = " + CurrentBar + " TickCount = " + Bars.TickCount) ; 
                                                  if (Close[0] > Close[1])
                                                          Value.Set(Value[1] + Bars.TickCount);
                                                  else if (Close[0]  < Close[1])
                                                          Value.Set(Value[1] - Bars.TickCount);
                                                  else
                                                          Value.Set(Value[1]);
                                          }                                       
                                  }
                          }
          ??

          Comment


            #6
            Hello tornadoatc,

            The Bars.TickCount will represents the total number of ticks of the current bar so if you are access it historically you are going to get the tick count of the current bar still, also if you have Calculate on bar close (COBC) set to true then you may get the tick count equal to 1 since the close of each bar will start the new bar as well which would be on the first tick as well.
            JCNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JC View Post
              Hello tornadoatc,

              The Bars.TickCount will represents the total number of ticks of the current bar so if you are access it historically you are going to get the tick count of the current bar still, also if you have Calculate on bar close (COBC) set to true then you may get the tick count equal to 1 since the close of each bar will start the new bar as well which would be on the first tick as well.
              The same data when evaluated on TradeStation does not operate this way. The tick count is available for each historical bar.

              Is there anyway to get any historical data where the tick count would be available for any data provider?

              Comment


                #8
                Hello tornadoatc,

                The only way that I am aware of to do something like would be to use a Multiseries script and Add a tick series to be able to count/calculate how many ticks are going to be are going to be used for each bar. You may see our Help Guide at the following link for more information on Multiseries scripts.

                JCNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rtwave, 04-12-2024, 09:30 AM
                5 responses
                37 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by funk10101, Today, 12:02 AM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by GLFX005, Today, 03:23 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by nandhumca, Yesterday, 03:41 PM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by The_Sec, Yesterday, 03:37 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X