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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X