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,



    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,



    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.

    The C# namespace alias qualifier `::` is used to access a member of an aliased namespace. The `::` operator is often used with the `global` alias, an alias for the global namespace


    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,



    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,

      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 The_Sec, Yesterday, 03:53 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by mmenigma, Yesterday, 03:25 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by kujista, Today, 05:44 AM
          0 responses
          7 views
          0 likes
          Last Post kujista
          by kujista
           
          Started by ZenCortexCLICK, Today, 04:58 AM
          0 responses
          9 views
          0 likes
          Last Post ZenCortexCLICK  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          172 responses
          2,282 views
          0 likes
          Last Post sidlercom80  
          Working...
          X