• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get the DateTime range of the PrimaryBars currently loaded in chart?

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

    How to get the DateTime range of the PrimaryBars currently loaded in chart?

    Hi there,

    I am building an Add On and I have a reference to the

    Code:
    ChartWindow.ActiveChartControl
    object. How can I, from this object, work out the date range of the currently load bars in the chart?

    Some sample code would be fantastic.

    Thanks for your time,

    codeowl.

    #2
    Hello codeOwl, and thank you for your question. The answer will not be quite straightforward, as the object you are referring to, by itself, will not be very useful for this. But we can make this information available to you when you are holding this object, and so I am going to attempt to answer that similar question.

    We can find documentation for the object you mentioned in a code sample here,

    http://ninjatrader.com/support/helpG...r_an_addon.htm

    This tells us that this object is visible during events such as OnWindowCreated. These events are, in turn, independent of information such as how many bars are on a particular chart. In spite of the name, Gui.Chart.ChartWindow has to do more with the actual window that a chart is displayed on, than the chart contained within the window.

    In an event like OnWindowCreated, chart bars will not yet be available, since the window will not have been populated. If you set up a custom user event at a time when you know bars have been populated, then information such as the time range displayed on your chart will necessarily also be available to you as a programmer. You can set up such an event with code such as this,

    http://ninjatrader.com/support/helpG...b=user%2Bevent

    I recommend triggering such an event from an Indicator. Within that indicator, you can use this publicly available MSDN C# documentation on globals to set aside any information you would like to make available to your add-on.

    https://msdn.microsoft.com/en-us/library/c3ay4x3d.aspx

    With that contextual information out of the way, I can give a more direct answer to your question. From within the indicator I am suggesting you use, you may access the displayed timespan via ChartControl.ShowDateRange. This is documented with code samples here,

    http://ninjatrader.com/support/helpG...properties.htm

    To clarify some of my wording and avoid confusion, I am assuming from your question that you are making an add-on, and if this is true, I am suggesting you make an indicator that works together with your add-on.

    Please let us know if there are any other ways we may help.
    Last edited by NinjaTrader_JessicaP; 11-09-2016, 08:23 AM.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_JessicaP,

      Thanks for taking the time to write a detailed response. Yes you are correct I am creating an Add-on.

      I understand that the Gui.Chart.ChartWindow is all about the window, but would have thought that the ChartWindow.ActiveChartControl would be all about the ChartControl, and I could have used this to get the DateTime range of the First to Last Primary Bar.

      Where you say:

      From within the indicator I am suggesting you use, you may access the displayed timespan via ChartControl.ShowDateRange. This is documented with code samples here,

      http://ninjatrader.com/support/helpG...properties.htm
      I had a look at this but the documentation says that the ShowDateRange property is:

      A bool indicating the date range of the bars painted on the visible chart canvas will be displayed within the chart
      I want to get access to the DateTime value of the first and last bar loaded in the chart when a user clicks a button on my Add On. I am not interested in getting the date range of the bars painted to be displayed within the chart.

      Is it possible for me to get the DateTime of the first and last bar loaded in the chart in the click event of a button created by my Add On?

      Thanks for your time,

      codeowl

      Comment


        #4
        NinjaTrader_JessicaP,

        I think I have worked it out mate. How does this look to you.

        This gets the first bar:

        Code:
        ChartWindow.ActiveChartControl.PrimaryBars.Bars.GetTime(0);  // For FDAX Returned   {8/11/2016 6:01:00 PM}
        This gets the last bar:

        Code:
        ChartWindow.ActiveChartControl.PrimaryBars.Bars.GetTime(_ChartWindow.ActiveChartControl.PrimaryBars.Bars.Count-1) // For FDAX Returned  {9/11/2016 8:00:00 AM}
        I am in Australia ;-)

        Regards,

        codeowl
        Last edited by codeowl; 11-10-2016, 05:09 AM.

        Comment


          #5
          Thank you for providing that code sample, this will help other users access this currently undocumented functionality.
          Jessica P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by levikNT, Today, 04:39 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by chartish, Today, 08:36 AM
          2 responses
          14 views
          0 likes
          Last Post chartish  
          Started by login_dejavu, Yesterday, 04:58 AM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_RyanS  
          Started by NinjaTrader_PaulH, Today, 07:40 AM
          0 responses
          4 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by awesometrader, Today, 06:59 AM
          2 responses
          9 views
          0 likes
          Last Post awesometrader  
          Working...
          X