• 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

GetBarIdxByTime do not work for me.

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

    GetBarIdxByTime do not work for me.

    I try to use GetBarIdxByTime to find value on exact time:

    protected override void OnBarUpdate()
    {
    if (ChartBars != null)
    {
    DateTime now = DateTime.Now;
    Print(now);
    DateTime preOpen = new DateTime(now.Year, now.Month, now.Day, 18, 59, 0);
    Print(preOpen);

    int barNum = ChartBars.GetBarIdxByTime(ChartControl, preOpen);
    Print(barNum);
    }
    }

    And on 1 minute chart a get following results:
    26.02.2019 23:31:21
    26.02.2019 18:59:00
    6416
    this is bar number and simultaneously minutes from now.
    But if we try to count 6416 minutes = ~107 hours! or 4,5 days!
    And that number does not change during the time.

    #2
    Hello igorvlassov,

    Thanks for your post.

    You are trying to get the time of a bar index that does not exist yet. This will not provide a reliable index because we do not know if we will receive data during that time to build that many bars. I have attached a demonstration explaining the output.

    Demo - https://drive.google.com/file/d/19SH...w?usp=drivesdk

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,
      Thanks a lot for the great video. But your explanation is based on slightly wrong basis. You assume that I want time in the future. But I need time in the past.
      If you check my first post carefully I had current time = 02.26.2019 23:31:21 and tried to find bar for 02.26.2019 18:59:00 ie ~6 hours back.
      I am in GMT + 4 time zone
      Seems I should set BarsRequiredToTrade = 600; // or so
      and use Bars.GetBar(DataTime)
      Last edited by igorvlassov; 02-27-2019, 07:12 AM.

      Comment


        #4
        Hello igorvlassov,

        Thank you for clarifying and pointing that out.

        GetBar and GetBarIdxByTime both can be used to get a bar index for a bar already on the chart. Keep in mind though, a BarIndex will be returned and the BarIndex will need to be converted to a BarsAgo index (subtracted from CurrentBar) to give a relative number of bars since the current bar. The index "6416" from your first post would mean that this is the 6416th bar on the chart.

        If there is anything else we can do to help, please let us know.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sawtooth500, Today, 12:59 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Spencer  
        Started by Steve L, Yesterday, 09:36 PM
        1 response
        19 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by MichaelAlexander, 04-25-2017, 03:28 AM
        9 responses
        1,170 views
        0 likes
        Last Post dani neira  
        Started by uday12, Today, 11:34 AM
        2 responses
        9 views
        0 likes
        Last Post uday12
        by uday12
         
        Started by Rober182, Today, 10:40 AM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X