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

Determining chart type in NT7

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

    Determining chart type in NT7

    A little bit of exploration I was doing recently has morphed into the general question of how you determine the type of chart (minute, tick, volume, etc.) to which an indicator or strategy has been added. (For the record, I exchanged some email with NT support about this one, but ultimately we got to the famous "Well, we could tell you, but then we'd have to kill you" point. Not entirely sure why this is a state secret....) Anyway, consider:

    The VolumeCounter indicator makes sure it's been applied to a volume chart with
    Code:
    if (Bars.Period.Id == PeriodType.Volume)
    in the override to the Plot() method. Easy enough. However, the TickCounter indicator uses
    Code:
    if (Bars.Period.Id == PeriodType.Tick ||
     (Bars.Period.BasePeriodType == PeriodType.Tick &&
     Bars.Period.Id != PeriodType.PointAndFigure &&
     Bars.Period.Id != PeriodType.Kagi &&
     Bars.Period.Id != PeriodType.LineBreak))
    in the Plot() method in order to isolate tick charts. And finally, RangeCounter uses
    Code:
    if (BarsArray[0].BarsType.BuiltFrom == Data.PeriodType.Tick &&
     BarsArray[0].Period.ToString().IndexOf("Range") >= 0)
        isRangeDerivate = true;
    within OnBarUpdate() and then uses
    Code:
    if (Bars.Period.Id == PeriodType.Range || isRangeDerivate)
    within Plot()!

    Clearly lots going on, most of which I can't explain. (I also noticed that Bars.Period.BasePeriodType always seemed to be PeriodType.Minute, and a couple of other people in a couple of other posts reported the same thing. Puzzling.)

    Can anyone shed any more light on this topic?

    #2
    PeriodType

    I think you have the answer already!
    PeriodType is an enum and lists all the available bar types ( volume, tick, minute,kagi, etc)

    To Test for it my guess would be

    if (Bars.Period.BasePeriodType == PeriodType.whatever)
    {do something}

    Comment


      #3
      Mike, please refer to the helpguide entry on PeriodType here - http://www.ninjatrader.com/support/h...barsperiod.htm

      An example is also included how you could check for certain type and interval used.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Bertrand: The helpguide entry basically says, Hey, there's a bunch of fields and they can take on a bunch of values. It is useless as far as being specific regarding what values what fields take on under what circumstances. If I simply read the helpguide entry and then set out to write VolumeCounter, TickCounter and RangeCounter on my own, I never would have ended up with anything close to the code that's supplied. But I'd like to think the code in those indicators is necessary and sufficient. Why are those tests to isolate tick and range charts done the way they're done?

        Mindset: Similar observation. If testing .PeriodType or .BasePeriodType were all that was needed, I would think the indicators would have been written that way. It's certainly possible that the indicators were written for a very early beta version when the fields were being used differently and then never changed even though the tests could have been simplified. But I don't want to assume that. I see a pretty complicated test to be sure a chart is a tick chart, and a pretty complicated test to be sure a chart is a range chart, and I'd really like to know whether or not that level of testing is required.

        Comment


          #5
          Mike, the indicators cited are not necessarily a guideline, they also make use of unsupported methods and have evolved over their lifetime...the helpguide article is very specific -

          if (BarsPeriod.Id == PeriodType.Tick && BarsPeriod.Value >= 100)
          {
          // We're dealing with a tick chart of an interval of 100 or greater...
          }

          The BasePeriod type checks have been added / exposed for the new chart types such a Point and figure or Kagi that we introduced with NT7, with it you can check from which base data those charts would be build.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Isn't TickCounter simply confirming that it's running on a tick chart? And isn't RangeCounter simply confirming that it's running on a range chart? If so, either the code in both cases is way too complex and could instead just check BarsPeriod.Id, or else in order to be really, truly, absolutely certain that I have a tick or range chart I need to resort to unsupported methods. I'd really like to know which it is....

            Comment


              #7
              As you can see from the code there's more to the Tick or Range counter than to check if they are running on a certain BarsPeriodId, for your custom indicator or strategy this check should suffice as laid out in the help docs.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Will TickCounter display its counter (as opposed to an error message) on any chart type other than a tick chart? If not, please explain why the simple test you're suggesting I should use is not sufficient for TickCounter.

                Comment


                  #9
                  Correct, the additional checks are used to determine if the used chart is offering bars built on a set # of ticks, as here the counter would make sense...I'm really not sure what the issue is you're dealing with - you can check for all types and intervals via programmatic access as outlined in the help docs and then do what's needed to produce suitable code for your needs.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Okay, I saw that TickCounter would display a tick count on a Renko chart. Except the counter message didn't fit on the screen and at times the count was negative. I kinda think that's just plain wrong.... (Note on the attachment there's a tiny little dot to the right of the -130, which is part of the next digit that is almost completely off the chart.)
                    Click image for larger version

Name:	Renko.jpg
Views:	1
Size:	40.6 KB
ID:	858676

                    Comment


                      #11
                      I see Mike, thanks for reporting this in - we will look into it.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Mike, can you please ensure you're on the latest NT7 beta as you test this? The most recent version of the TickCounter should yield the error on Renko bars, too.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Trick seems to be this: 1. Create a Kagi chart that is tick-based. 2. Add TickCounter indicator. (You'll get TickCounter's error message.) 3. Change chart type to Renko. Bingo!

                          I do see that if you create a Renko chart and put TickCounter on it you get the error message. But the sequence above – creating a Kagi chart first – should show the incorrect output.

                          BTW, back to the original question: It sure looks like TickCounter only wants to display a count on tick charts (i.e., where Type=Tick in the Data Series dialog). If so, I'm still mystified as to why it performs a test more complicated than BarsPeriod.Id == PeriodType.Tick.

                          Comment


                            #14
                            Thanks, we'll recheck that scenario - TickCounter simply covers more cases than being on a tick solely applied.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Can you give me an example of a case where TickCounter won't produce its error message other than a chart where Type is set to Tick, which I believe would be equivalent to BarsPeriod.Id == PeriodType.Tick? I know I've essentially come back around to my original question of what all that messy code accomplishes, but I still don't see it. An example would help.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,281 views
                              0 likes
                              Last Post Leafcutter  
                              Started by WHICKED, Today, 12:45 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by Tim-c, Today, 02:10 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Taddypole, Today, 02:47 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Taddypole  
                              Started by chbruno, 04-24-2024, 04:10 PM
                              4 responses
                              53 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Working...
                              X