• 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

Current daily bar's Open data

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

    Current daily bar's Open data

    Is there is another way to retrieve the current daily bar's Open price other than setting the calculation method to calculate after each tick? I.E. is there another way of retrieving the current daily bar's Open price using Calculate.OnBarClose?

    Thanks

    #2
    Hello chnh1,

    A bar series has to update to get that information. (Unless you are wanting to use OnMarketData() and trigger actions in real-time)

    You can add an additional tick series (or minute series if you are fine waiting for a minute bar to close) to your script to trigger actions intra-bar (intra day bar in this case).
    A bool can be used that is set to true when the primary bar has closed and set back to false after the next bar with the added series received (or minute bar closes).

    Code:
    private bool primaryClosed;
    
    in OnStateChange:
    else if (State == State.Configure)
    {
    	AddDataSeries(BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    	primaryClosed = false;
    }
    
    in OnBarUpdate:
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    	return;
    
    if (BarsInProgress == 0)
    {
    	primaryClosed = true;
    	// this is the primary series closing. the open of which should match the first tick or first minute's open
    	Print(string.Format("{0} | bip0 | open: {1}, high: {2}, low: {3}, close: {4}", Times[0][0], Opens[0][0], Highs[0][0], Lows[0][0], Closes[0][0]));
    }
    else if (primaryClosed)
    {
    	primaryClosed = false;
    	// this is the first bar of the added series
    	Print(string.Format("{0} | bip1 | open[1]: {1}", Times[1][0], Opens[1][0]));
    }
    Last edited by NinjaTrader_ChelseaB; 04-25-2018, 07:35 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by superg3, Today, 12:33 AM
    0 responses
    3 views
    0 likes
    Last Post superg3
    by superg3
     
    Started by vppzepuq, Yesterday, 11:28 PM
    0 responses
    2 views
    0 likes
    Last Post vppzepuq  
    Started by Steve L, 05-25-2019, 10:04 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by mestril, 05-25-2019, 10:22 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by hir04068, 05-25-2019, 09:29 PM
    7 responses
    22 views
    0 likes
    Last Post hir04068  
    Working...
    X