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

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.
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Carolscogginsi, Today, 10:45 PM
    0 responses
    2 views
    0 likes
    Last Post Carolscogginsi  
    Started by RaddiFX, Today, 10:15 AM
    2 responses
    14 views
    0 likes
    Last Post RaddiFX
    by RaddiFX
     
    Started by patrickmlee007, Today, 09:33 AM
    2 responses
    18 views
    0 likes
    Last Post patrickmlee007  
    Started by magnatauren, 08-15-2020, 02:12 PM
    5 responses
    206 views
    0 likes
    Last Post RaddiFX
    by RaddiFX
     
    Started by rene69851, 05-02-2024, 03:25 PM
    1 response
    22 views
    0 likes
    Last Post rene69851  
    Working...
    X