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 NullPointStrategies, Today, 05:17 AM
      0 responses
      37 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      64 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      41 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