Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compare price from yesterday

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

    Compare price from yesterday

    Hi,

    I am struggling with two connected issues in what appears to be a simple price comparison. The following line of code is trying to compare the price at 7:10 to a price yesterday which is 300 1-min bars ago.

    if (Close[0] > Close[300] && ToTime(Time[0]) == ToTime(7, 10, 0))

    [1] The first problem is that a look back 300 bars ago doesn't appear to work. It does work for smaller numbers like 10 but I'm assuming there is some limit here. What I really would prefer is to be able to specify the exact time I am interested in, for example yesterday's 14:30 or 16:30 price. So, first question, is there a limit on how many bars I can specify and better still can I specify a time to take a price from instead?

    [2] There is a second problem with me choosing this 7:10 time. For a low volume market during the first hours of electronic trading, it is possible that there is no bar for a given minute as nothing has traded. On the face of it, that means that if I generically look back 300 bars I will get back to differing times in yesterday which is far from ideal. I thought that maybe if I specified that the market hours were set to start at 7:10 then I could get rid of the random bar issue but I can't see a way of specifying a bespoke trading period for a market and even if I can, this may be only for charting purposes and the underlying strategy may still read all the available data anyway. Is this correct?

    Many thanks,
    darmbk.

    #2
    darmbk, if you check your Control Center log tab, any errors mentioned there when you run your study?

    You are likely running into with referencing this many bars back - http://www.ninjatrader.com/support/f...ead.php?t=3170

    You could work with GetBar() though as alternative - http://www.ninjatrader.com/support/h...ightsub=Getbar

    Correct, there's no guarantee you would see at 1 min bar at your specified time - it depends on the market and liquidity. You could look into running on a custom session template, those would define the times for the charting and also for any scripts run on this chart then - you can setup under Tools > Session Manager.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X