RectangleExtension indicator - does what you ask for. Have the week off 
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
using System.Reflection;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.MA5
{
public class RectangleExtension : Indicator
{
// private DateTime curDate = DateTime.Parse(“2/26/2023 12:00:00 AM”);
private NinjaTrader.Gui.Chart.Chart chartWindow;
private new System.Windows.Controls.Button Expansion;
private bool IsToolBarButtonAdded;
private TimeSpan timeEndS;
private DateTime startTime;
private DateTime endTime;
private bool showAreaColor;
private Brush rectColor;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @“Rectangle extender. Extend the selected rectangle to the end time of current day.”;
Name = “Rectangle Extension”;
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
startTime = DateTime.Now;
endTime = startTime.Add(TimeEnd);
TimeEnd = new TimeSpan(23, 50, 00);
ShowAreaColor = true;
RectColor = Brushes.LightCyan;
}
#region Button //Real RealTime
else if (State == State.Realtime)
{
if (ChartControl != null && !IsToolBarButtonAdded)
{
ChartControl.Dispatcher.InvokeAsync((Action)(() =>
{
AddButtonToToolbar();
}));
}
}
else if (State == State.Terminated)
{
if (chartWindow != null)
{
ChartControl.Dispatcher.InvokeAsync((Action)(() =>
{
DisposeCleanUp();
}));
}
}
#endregion
}
#region Button
private void AddButtonToToolbar()
{
chartWindow = Window.GetWindow(this.ChartControl.Parent) as Chart;
if (chartWindow == null)
{
Print(“chartWindow == null”);
return;
}
Style btnStyle = new Style();
btnStyle.TargetType = typeof(System.Windows.Controls.Button);
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontSizeProperty, 11.0));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontFamilyProperty, new FontFamily(“Franklin Gothic Book”)));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.FontWeightProperty, FontWeights.Bold));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.MarginProperty, new Thickness(2, 0, 2, 0)));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.PaddingProperty, new Thickness(4, 2, 4, 2)));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.ForegroundProperty, Brushes.Cyan));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.BackgroundProperty, Brushes.Transparent));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.IsEnabledProperty, true));
btnStyle.Setters.Add(new Setter(System.Windows.Controls.Button.HorizontalAlignmentProperty, HorizontalAlignment.Center));
Expansion = new System.Windows.Controls.Button();
Expansion.Content = “Extension”;
Expansion.Style = btnStyle;
chartWindow.MainMenu.Add(Expansion);
Expansion.Visibility = Visibility.Visible;
Expansion.Click += ExpansionClick;
IsToolBarButtonAdded = true;
}
#endregion
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
}
private void ExpansionClick(object sender, RoutedEventArgs e)
{
System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
if (button != null)
{
foreach(IDrawingTool drawObject in DrawObjects)
{
if(drawObject.GetType().ToString().Contains(“Rectangle”))
{
endTime = endTime.Add(TimeEnd);
dynamic rectangle = drawObject;
if(drawObject.IsSelected)
{
if (ShowAreaColor){ rectangle.AreaBrush = RectColor; }
((Rectangle) drawObject).EndAnchor = new ChartAnchor(endTime, ((Rectangle) drawObject).EndAnchor.Price, ChartControl);
// another option, which also works.
// ((Rectangle) drawObject).EndAnchor = new ChartAnchor(curDate, ((Rectangle) drawObject).EndAnchor.Price, ChartControl);
}
}
}
chartWindow.ActiveChartControl.InvalidateVisual();
ForceRefresh();
}
}
private void DisposeCleanUp()
{
if (Expansion != null) chartWindow.MainMenu.Remove(Expansion);
Expansion.Click -= ExpansionClick;
}
#region Properties
// [NinjaScriptProperty]
// [PropertyEditor(“NinjaTrader.Gui.Tools.TimeEditorKey”)]
// [Display(ResourceType = typeof(Custom.Resource), Name = “End Time”, GroupName = “Parameters”, Order = 04)]
// public DateTime CurDate
// { get; set; }
\[XmlIgnore\]
\[Browsable(false)\]
public TimeSpan TimeEnd
{ get; set; }
\[NinjaScriptProperty\]
\[Display(Name = "Time End", GroupName = "Parameters", Order = 01)\]
public string TimeEndSpanSerialize
{
get { return TimeEnd.ToString(); }
set { TimeEnd = TimeSpan.Parse(value); }
}
\[Display(Name="Show Area Color", Order = 02, GroupName="Parameters")\]
public bool ShowAreaColor
{ get; set; }
\[XmlIgnore\]
\[Display(Name="Rectangle Color", Order = 03, GroupName="Parameters")\]
public Brush RectColor
{ get; set; }
\[Browsable(false)\]
public string RectColorSerializable
{
get { return Serialize.BrushToString(RectColor); }
set { RectColor = Serialize.StringToBrush(value); }
}
#endregion
#region Hide names
public override string DisplayName
{
get { if (State == State.SetDefaults){ return GetIndDisplay();}
else{ return “”; }}}
protected string GetIndDisplay() {
try { string[] split = Instrument.FullName.Split(new char[] {’ '});
string CrSy = split[0]; return CrSy + “Rectangle Extension”; } catch (Exception ex) { return “”;}
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MA5.RectangleExtension[] cacheRectangleExtension;
public MA5.RectangleExtension RectangleExtension(string timeEndSpanSerialize)
{
return RectangleExtension(Input, timeEndSpanSerialize);
}
public MA5.RectangleExtension RectangleExtension(ISeries input, string timeEndSpanSerialize)
{
if (cacheRectangleExtension != null)
for (int idx = 0; idx < cacheRectangleExtension.Length; idx++)
if (cacheRectangleExtension[idx] != null && cacheRectangleExtension[idx].TimeEndSpanSerialize == timeEndSpanSerialize && cacheRectangleExtension[idx].EqualsInput(input))
return cacheRectangleExtension[idx];
return CacheIndicator<MA5.RectangleExtension>(new MA5.RectangleExtension(){ TimeEndSpanSerialize = timeEndSpanSerialize }, input, ref cacheRectangleExtension);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MA5.RectangleExtension RectangleExtension(string timeEndSpanSerialize)
{
return indicator.RectangleExtension(Input, timeEndSpanSerialize);
}
public Indicators.MA5.RectangleExtension RectangleExtension(ISeries input , string timeEndSpanSerialize)
{
return indicator.RectangleExtension(input, timeEndSpanSerialize);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MA5.RectangleExtension RectangleExtension(string timeEndSpanSerialize)
{
return indicator.RectangleExtension(Input, timeEndSpanSerialize);
}
public Indicators.MA5.RectangleExtension RectangleExtension(ISeries input , string timeEndSpanSerialize)
{
return indicator.RectangleExtension(input, timeEndSpanSerialize);
}
}
}
#endregion