Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rectangle Plotting 2 days

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

    Rectangle Plotting 2 days

    Hello,

    from the helpguide and the forum I know how to plot a rectangle a specific time of day. But I can´t find the solution for plotting the rectangle with a start time > stop time of plotting. The start time is eg at 16:00 where it should start to plot and the stop time of plotting eg is 9:00.

    Now I have from an indicator

    int BarMinute = Time[1].Minute;
    int BarHour = Time[1].Hour;
    int BarDay = Time[1].Day;
    int BarMonth = Time[1].Month;
    int BarYear = Time[1].Year;
    int start = CurrentBars[1]-Bars.GetBar(new DateTime(BarYear, BarMonth, BarDay, StartHour, StartMinute,0));
    int stop = CurrentBars[1]-Bars.GetBar(new DateTime(BarYear, BarMonth, BarDay, StopHour, StopMinute,0));

    if (xNow.Date==Times[0][0].Date && start >= 0 && stop <= 0 )
    {Draw.Rectangle(this,"hl", true, new DateTime (BarYear,BarMonth, BarDay,StartHour, StartMinute,0), lowtz1, new DateTime (BarYear, BarMonth, BarDay,StopHour, StopMinute,0), hightz1, timecolor, timecolor, Opacity);}

    What is to change please so that it plots the rectangle from yesterday 16:00 untill today 9:00 (for every day).

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thanks for your post.

    I have a hard time following your code so here is an example that you can refer to on how to use DateTime to draw across the dates.

    Code:
                if (Time[0].TimeOfDay == new TimeSpan(16,00,00))
                {
                    end_Time = Time[0].AddDays(1);  // draw to the next day
                    end_Time = end_Time.AddHours(-7);  // 16:00 - 7 hours = 9:00 AM
    
                    Draw.Rectangle(this,"test"+Time[0], Time[0], Low[0], end_Time, High[0], Brushes.Gold);                
                }
    This was written based on that you would have a tick at 4:00 PM. If you are using non time based bars or are trying to draw exactly at the end of a session you may want to use a range of time and then bool logic so you are only drawing once per time period.

    Notes:
    end_Time was created as private DateTime end_Time;
    end_Time is seeded with the current bars Date and Time which would be 16:00 and whatever date it is.
    Using .AddDays(1) will add a day to end_Time which then makes the end_Time have the next day date
    Using AddHours(-7) subtracts 7 hours from the time of 16:00 which makes the end_Time at 9:00 AM

    Comment

    Latest Posts

    Collapse

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