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

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 mattbsea, Today, 05:44 PM
    0 responses
    3 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    31 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    2 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,282 views
    0 likes
    Last Post Leafcutter  
    Started by WHICKED, Today, 12:45 PM
    2 responses
    20 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Working...
    X