• 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
    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

  • 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:

Latest Posts

Collapse

Topics Statistics Last Post
Started by zweistein, 11-14-2017, 03:24 PM
2 responses
1,476 views
0 likes
Last Post woodie1
by woodie1
 
Started by Newtrader101, Today, 04:50 AM
3 responses
18 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by utilizator, Today, 06:31 AM
3 responses
13 views
0 likes
Last Post NinjaTrader_Jesse  
Started by digibob, Today, 01:13 AM
3 responses
14 views
0 likes
Last Post digibob
by digibob
 
Started by calebsandfort, Yesterday, 05:16 PM
2 responses
11 views
0 likes
Last Post NinjaTrader_PaulH  
Working...
X