How to Draw a Rectangle Box in ThinkorSwim

Stewart

New member
Is there a script for me to draw in my own Supply and Demand Zones? Not automated by the computer.

I know I can draw a box, but I would like to be able to make a rectangle around one or 2 bars, then have that rectangle go on into infinity to the right. It seems simple. Has anyone done this? It would be nice if the box would show the price range and maybe have the supply zone be one color and the demand zone a different color.

Any help would be appreciated.

Thank You
 

Stewart

New member
Thank you. I understand there is a rectangle.
But I would like to draw the rectangle over one or 2 bars and have the computer automatically extend the bar all the way to the right of the screen.

I’m looking at zones that may have started many bars ago.

Can that basic rectangle be modified to do that?
 

horserider

Well-known member
VIP
@Stewart You can do this in a somewhat tedious way. Draw your box. Left click on the box. Edit Properties. Change the date for one of the lower box to the date you wish to extend till. The box will then expand to that date.
 

TCB

Member
Hi, I have started to write this script that plots rectangular boxes on the chart and it works but I want it to show only on the current intraday chart. As is stands now, if you scroll back it shows on previous days. I can't seem to figure this out. Does anyone know what I need to do to correct this problem? I would really appreciate any help, thanks! I have included the script below:

Code:
Created 4-13-21 by TCB

input ShowTodayOnly={"No", default "Yes"};
input alertPeriodStart = 930;
input alertPeriodEnd = 1130;
def Today = if GetLastDay() == GetDay() then 1 else 0;
def StartAlertPeriod = SecondsTillTime(alertPeriodStart);
def EndAlertPeriod = SecondsTillTime(alertPeriodEnd);
def AlertPeriod = If (StartAlertPeriod <= 0 and EndAlertPeriod > 0, close, 0);

input PutLevelStart = 0.0;
input CallLevelStart = 0.0;
input Range = 0.0;

input HideBoxLines = Yes;
input HideLabels = Yes;

def PutTopBox = PutLevelStart + Range;
def CallBottomBox = CallLevelStart - Range;

plot TopArea = HighestAll (if AlertPeriod then PutTopBox else Double.NaN);
TopArea.SetDefaultColor(Color.GRAY);
TopArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TopArea.SetHiding(HideBoxLines);

plot BottomArea = HighestAll (if AlertPeriod then CallBottomBox else Double.NaN);
BottomArea.SetDefaultColor(Color.GRAY);
BottomArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BottomArea.SetHiding(HideBoxLines);

plot PutBBox = LowestAll (if AlertPeriod then PutLevelStart else Double.NaN);
PutBBox.SetDefaultColor(Color.GRAY);
PutBBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PutBBox.SetHiding(HideBoxLines);

plot CallTBox = HighestAll (if AlertPeriod then CallLevelStart else Double.NaN);
CallTBox.SetDefaultColor(Color.GRAY);
CallTBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CallTBox.SetHiding(HideBoxLines);

AddCloud(if AlertPeriod then TopArea else Double.NaN, if AlertPeriod then PutBBox else Double.NaN, Color.GRAY, Color.GRAY);
AddCloud(if AlertPeriod then BottomArea else Double.NaN, if AlertPeriod then CallTBox else Double.NaN, Color.GRAY, Color.GRAY);
 

SleepyZ

Active member
Hi, I have started to write this script that plots rectangular boxes on the chart and it works but I want it to show only on the current intraday chart. As is stands now, if you scroll back it shows on previous days. I can't seem to figure this out. Does anyone know what I need to do to correct this problem? I would really appreciate any help, thanks! I have included the script below:

Code:
Created 4-13-21 by TCB

input ShowTodayOnly={"No", default "Yes"};
input alertPeriodStart = 930;
input alertPeriodEnd = 1130;
def Today = if GetLastDay() == GetDay() then 1 else 0;
def StartAlertPeriod = SecondsTillTime(alertPeriodStart);
def EndAlertPeriod = SecondsTillTime(alertPeriodEnd);
def AlertPeriod = If (StartAlertPeriod <= 0 and EndAlertPeriod > 0, close, 0);

input PutLevelStart = 0.0;
input CallLevelStart = 0.0;
input Range = 0.0;

input HideBoxLines = Yes;
input HideLabels = Yes;

def PutTopBox = PutLevelStart + Range;
def CallBottomBox = CallLevelStart - Range;

plot TopArea = HighestAll (if AlertPeriod then PutTopBox else Double.NaN);
TopArea.SetDefaultColor(Color.GRAY);
TopArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TopArea.SetHiding(HideBoxLines);

plot BottomArea = HighestAll (if AlertPeriod then CallBottomBox else Double.NaN);
BottomArea.SetDefaultColor(Color.GRAY);
BottomArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BottomArea.SetHiding(HideBoxLines);

plot PutBBox = LowestAll (if AlertPeriod then PutLevelStart else Double.NaN);
PutBBox.SetDefaultColor(Color.GRAY);
PutBBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PutBBox.SetHiding(HideBoxLines);

plot CallTBox = HighestAll (if AlertPeriod then CallLevelStart else Double.NaN);
CallTBox.SetDefaultColor(Color.GRAY);
CallTBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CallTBox.SetHiding(HideBoxLines);

AddCloud(if AlertPeriod then TopArea else Double.NaN, if AlertPeriod then PutBBox else Double.NaN, Color.GRAY, Color.GRAY);
AddCloud(if AlertPeriod then BottomArea else Double.NaN, if AlertPeriod then CallTBox else Double.NaN, Color.GRAY, Color.GRAY);
Here is an example for one of the plots that you could use for all if this works for you:
Code:
plot TopArea = if showtodayOnly and !today then double.nan else HighestAll (if AlertPeriod then PutTopBox else Double.NaN) ;
 

TCB

Member
Here is an example for one of the plots that you could use for all if this works for you:
Code:
plot TopArea = if showtodayOnly and !today then double.nan else HighestAll (if AlertPeriod then PutTopBox else Double.NaN) ;
Hey thank you so much!
 
Last edited:

SleepyZ

Active member
Hey thanks but when I added that to both of the plots it did not draw anything on my chart. Any suggestions?
Here is the example expanded to the other plots. I had to add some values to your put, call and range to test the boxes with the code modifications.

Capture.jpg


input ShowTodayOnly={"No", default "Yes"};
input alertPeriodStart = 930;
input alertPeriodEnd = 1130;
def Today = if GetLastDay() == GetDay() then 1 else 0;
def StartAlertPeriod = SecondsTillTime(alertPeriodStart);
def EndAlertPeriod = SecondsTillTime(alertPeriodEnd);
def AlertPeriod = If (StartAlertPeriod <= 0 and EndAlertPeriod > 0, close, 0);

input PutLevelStart = 0.0;
input CallLevelStart = 0.0;
input Range = 0.0;

input HideBoxLines = Yes;
input HideLabels = Yes;

def PutTopBox = PutLevelStart + Range;
def CallBottomBox = CallLevelStart - Range;

plot TopArea = if showtodayOnly and !today then double.nan else HighestAll (if AlertPeriod then PutTopBox else Double.NaN) ;
TopArea.SetDefaultColor(Color.GRAY);
TopArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TopArea.SetHiding(HideBoxLines);

plot BottomArea = if showtodayOnly and !today then double.nan else HighestAll (if AlertPeriod then CallBottomBox else Double.NaN);
BottomArea.SetDefaultColor(Color.GRAY);
BottomArea.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BottomArea.SetHiding(HideBoxLines);

plot PutBBox = if showtodayOnly and !today then double.nan else LowestAll (if AlertPeriod then PutLevelStart else Double.NaN);
PutBBox.SetDefaultColor(Color.GRAY);
PutBBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PutBBox.SetHiding(HideBoxLines);

plot CallTBox = if showtodayOnly and !today then double.nan else HighestAll (if AlertPeriod then CallLevelStart else Double.NaN);
CallTBox.SetDefaultColor(Color.GRAY);
CallTBox.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CallTBox.SetHiding(HideBoxLines);

AddCloud(if AlertPeriod then TopArea else Double.NaN, if AlertPeriod then PutBBox else Double.NaN, Color.GRAY, Color.GRAY);
AddCloud(if AlertPeriod then BottomArea else Double.NaN, if AlertPeriod then CallTBox else Double.NaN, Color.GRAY, Color.GRAY);
 
  • Like
Reactions: TCB

Similar threads

Top