• 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 the price of a bar by time

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

  • NinjaTrader_Ray
    replied
    imported post

    Then just change the parameters you pass in to reflect the bar date.

    replace DateTime.Now.Year with Time[0].Year

    as an example.

    Ray

    Leave a comment:


  • BradB
    replied
    imported post

    Unfortunately I don't seem to be able to back test with this method. It keeps using the current date/time, instead of the date/time of that day. Is there any other way to retrieve a closing price from a specific date/time?

    Leave a comment:


  • NinjaTrader_Ray
    started a topic How to get the the price of a bar by time

    How to get the the price of a bar by time

    The method "Bars.GetBar(DateTime time)" returns the bar index value representing thefirstbar (from left to right)holdingthe specified time.

    For example:

    int barsAgo = CurrentBar - Bars.GetBar(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 0, 0, 0));
    double closingPrice = Close[barsAgo];




    Ray

Latest Posts

Collapse

Topics Statistics Last Post
Started by _Zero_, 12-31-2019, 09:18 AM
17 responses
155 views
1 like
Last Post aviat72
by aviat72
 
Started by billythekid72, Today, 09:47 AM
2 responses
6 views
0 likes
Last Post billythekid72  
Started by JohnS52, Today, 09:49 AM
0 responses
6 views
0 likes
Last Post JohnS52
by JohnS52
 
Started by DTSSTS, Today, 08:29 AM
3 responses
23 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by mtamaku, Today, 08:39 AM
3 responses
15 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X