Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Line at Open of Month

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

    Line at Open of Month

    Good Day Everyone,
    Im trying to create a line at the session open of the first day of the month and extend the line to the last day of the month, but having some trouble here. The below code only works if the prior bar was a different month. If a new month starts mid week, its thrown off because prior bar wasnt a different month since the line starts at session open. What would be the best route to take to correct that? Any advice is welcome.


    Code:
    if (Time[1].Month != Time[0].Month)
    {
         sTime = Time[0].Date.AddHours(18).AddMinutes(BarVal);
         eTime = Time[0].Date.AddDays(DateTime.DaysInMonth(Time[0].Year, Time[0].Month)).AddHours(17);
    
         if (Time[0] == sTime)
         {
              sPrice = Open[0];
         }
    }​
    Last edited by ChrisR; 06-05-2023, 12:05 PM.

    #2
    Hello, thanks for writing in. The support team will unfortunately not be able to fix or create any new code. Another member of the forum would need to volunteer for this. We have an example that may help linked below:

    Multi functional repeater of up to 10 X and/or Y Highlight regions daily or day of week. User interface expands for up to 10 events. Each event configurable as a time region, price region, fixed rectangle or dynamic rectangle (adjusts on price), select a day of the week or daily. Here is a quick video […]


    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello, thanks for writing in. The support team will unfortunately not be able to fix or create any new code. Another member of the forum would need to volunteer for this. We have an example that may help linked below:

      Multi functional repeater of up to 10 X and/or Y Highlight regions daily or day of week. User interface expands for up to 10 events. Each event configurable as a time region, price region, fixed rectangle or dynamic rectangle (adjusts on price), select a day of the week or daily. Here is a quick video […]


      The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
      Im not asking for anyone to fix or create code, simply asking what would be the best route to take to do what I want to do. Perhaps a member will be able to asist. That repeater indicator linked Im not sure is relevant to what I'm looking to do.

      Comment


        #4
        So I have reworked the above code a bit and have the start and end times for the line correct. I'm flipping a bool to true when the month changes and capturing the next session open time, which is the months open time. For end time, Im just adding days remaining in month minus current day number to the start time. Than flipping bool to false. This is working fine.

        The issue I am running into is its using prior months open price for historical bars while in real-time its returning current months open, verified with Print statements. When the monthly open line is drawn, its referencing the prior months open price, not current (forming) months open.

        Any advice from the forum is welcome.


        Code:
                DateTime sTime, eTime;
                private double sPrice;
                private bool mSwitch = false;​
        Code:
        else if (State == State.Configure)
        {
             AddDataSeries(Data.BarsPeriodType.Month, 1);
        }​
        Code:
        if (CurrentBar >= 2 && Time[1].Month != Time[0].Month)
             mSwitch = true;
        
        if (mSwitch && Time[0] == Time[0].Date.AddHours(18).AddMinutes(BarVal))
             {
                  sTime = Time[0].Date.AddHours(18).AddMinutes(BarVal);
                  eTime = sTime.AddDays(DateTime.DaysInMonth(Time[0].Year, Time[0].Month)-Time[0].Day).AddHours(-1).AddMinutes(-BarVal);
                  mSwitch = false;
             }
        
         if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
              return;    
        
        sPrice = Opens[1][0];​
        Last edited by ChrisR; 06-06-2023, 02:47 PM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        560 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        325 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X