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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    127 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X