• 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, 06:35 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Newtrader101, Today, 10:46 AM
    3 responses
    7 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by tecmisc1, Today, 10:42 AM
    1 response
    5 views
    0 likes
    Last Post tecmisc1  
    Started by behindthewheel, Today, 10:39 AM
    0 responses
    5 views
    0 likes
    Last Post behindthewheel  
    Started by ballboy11, Today, 10:35 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by fredfred, Today, 10:30 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Melissa  
    Working...
    X