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

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 yertle, Today, 08:38 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by love2code2trade, Yesterday, 01:45 PM
        3 responses
        22 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by trilliantrader, Today, 08:16 AM
        2 responses
        6 views
        0 likes
        Last Post trilliantrader  
        Started by samish18, Today, 08:31 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by Creamers, 09-08-2023, 10:26 AM
        6 responses
        157 views
        0 likes
        Last Post JonyGurt  
        Working...
        X