Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Monthly Open Price

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

    Current Monthly Open Price

    Hello,

    I want to be able to access the monthly open price in a strategy when the monthly bar has yet to close (current month). So for example, today in my strategy I want to access this month's open price from 3/1/19.

    How would I go about doing that?

    Thanks.

    #2
    Hello fiddich,

    Thank you for your post.

    This will depend on the calculate setting you want to use, and the modes you want to use the strategy in. If this is for realtime only and you are using OnEachTick or OnPriceChange, you can add a secondary Monthly series and just use the 0 BarsAgo open price from that series.

    If you are using OnBarClose or wanted to do this historically, that will be more difficult as you would only have access to the last Closed bar from the current Closed bar. Some options at accessing this value may include using logic to find the first day of the month and then get the values from that point in time however this may not exactly match the monthly bar open. Another approach could be using a secondary daily series to access the first days values. Again this may differ than the monthly bar however this would likely be closer as monthly bars are built using daily bars. For both of these items, these are not a concept that I have a specific sample of that I could provide, unfortunately.

    I was able to quickly create a sample that uses a daily series to find the open of the first day of the month, you may try using something like the following:
    Code:
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    AddPlot(Brushes.Red, "test");
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Day, 1);
                }
            }
    
            double monthOpen = 0;
            protected override void OnBarUpdate()
            {
                if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                if(BarsInProgress == 1)
                {
                    if(Time[0].Day == 1)
                    {
                        monthOpen = Open[0];    
                    }
                }
                if(BarsInProgress != 0) return;
                Value[0] = monthOpen;
            }
    I look forward to being of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello fiddich,

      Thank you for your post.

      This will depend on the calculate setting you want to use, and the modes you want to use the strategy in. If this is for realtime only and you are using OnEachTick or OnPriceChange, you can add a secondary Monthly series and just use the 0 BarsAgo open price from that series.

      If you are using OnBarClose or wanted to do this historically, that will be more difficult as you would only have access to the last Closed bar from the current Closed bar. Some options at accessing this value may include using logic to find the first day of the month and then get the values from that point in time however this may not exactly match the monthly bar open. Another approach could be using a secondary daily series to access the first days values. Again this may differ than the monthly bar however this would likely be closer as monthly bars are built using daily bars. For both of these items, these are not a concept that I have a specific sample of that I could provide, unfortunately.

      I was able to quickly create a sample that uses a daily series to find the open of the first day of the month, you may try using something like the following:
      Code:
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      AddPlot(Brushes.Red, "test");
      }
      else if (State == State.Configure)
      {
      AddDataSeries(BarsPeriodType.Day, 1);
      }
      }
      
      double monthOpen = 0;
      protected override void OnBarUpdate()
      {
      if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
      if(BarsInProgress == 1)
      {
      if(Time[0].Day == 1)
      {
      monthOpen = Open[0];
      }
      }
      if(BarsInProgress != 0) return;
      Value[0] = monthOpen;
      }
      I look forward to being of further assistance.
      Jesse, or whoever can answer as this is from 2014, but...

      if (Time[0].Day == 1)

      This is assuming the first of the month is a trading day. If the first trading day of the month is the 2nd, this will not work. Whats the workaround for that?

      Comment


        #4
        Hello ChrisR,

        If you are using an instrument which has trading days that fall off the first you would have to add additional conditions to make sure a value was set.

        Code:
        if(monthOpen <= 0 && Time[0].Day == 2)
        {
            monthOpen = Open[0];
        }

        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
        126 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