Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Prior Day Close And Today's Open

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

    Getting Prior Day Close And Today's Open

    I'm having a lot of trouble trying to figure this out. Maybe I'm thinking about this the wrong way?

    I got the previous day close by adding another data series:

    Code:
    AddDataSeries(BarsPeriodType.Day, 1);

    When I output
    Code:
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0)
    return;​
    
    Closes[1][0];
    When i run the strategy, I get the close from 3 days ago first. Then when the it runs again, I get the 2nd day. And the third time it runs, I get 1 day ago (which is what I'm looking for).
    Why doesn't it get the previous day the first time?

    I also do not know how to get the current day's open (not pre-market). I thought I could use the same day data series, but this is not working.
    Any ideas?

    #2
    Regarding getting current day's RTH open, assuming you are using an ETH data series - one approach is to get Open[0] when Time[0] is the market's open time (i.e. 9:30am EST) OR you'll need to add an additional RTH data series.

    Code:
    private double rthOpen = 0;  // Variable to store RTH open
    
    protected override void OnBarUpdate()
    {
        // Ensure this logic only runs for the primary minute bar data series
        if (BarsInProgress != 0) return;  // Check if the current data series triggering OnBarUpdate is the primary series
    
        // Check if there is enough data
        if (CurrentBar < 1) return;
    
        // Define RTH start time
        TimeSpan rthStartTime = new TimeSpan(9, 30, 0);  // 9:30 AM ET
    
        // Check if the bar's time matches RTH start time (assuming 1-minute bars for the primary series)
        if (ToTime(Time[0]) == ToTime(rthStartTime))
        {
            // Store the open of the bar which corresponds to the RTH open
            rthOpen = Open[0];
            // Print the RTH open; useful for debugging or real-time monitoring
            Print("Today's RTH open was: " + rthOpen);
        }
    }
    ​
    Last edited by FaaastEddy; 02-26-2025, 06:45 PM.

    Comment


      #3
      Hello,

      Thank you for your post.

      You can use the PriorDayOHLC and CurrentDayOHL indicators to get these values.



      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      47 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X