private bool DoItOnce = true, keepDrawing = true;
private int startBar;
private double rect_high, rect_low;
if (State != State.Realtime) return; // just use realtime data for this example
if (DoItOnce)
{
startBar = CurrentBar - 30; // pick a startpoint
rect_high = High[30]; // pick a high level
rect_low = Low[30]; // pick a low level
Draw.Rectangle (this, "test", (CurrentBar - startBar), rect_high, 0, rect_low, Brushes.Cornsilk, true); //draw first rect.
DoItOnce = false; // set bool false so we only draw initial once
}
else if (keepDrawing)
{
Draw.Rectangle (this, "test", (CurrentBar - startBar), rect_high, 0, rect_low, Brushes.Cornsilk, true); // redraw (extend) rectangle to current bar
}
if (CrossAbove(High, rect_low, 1) || CrossBelow(Low, rect_high, 1)) // test to see if boundaries crossed and if so stop drawing.
keepDrawing = false;
Example 2 This plots multiple rectangles
private bool DoItOnce = true, keepDrawing = true,swingStart = true;
private int mystartBar;
private double rect_high, rect_low,rect_close1,rect_close2;
int myCounter = 1;
string myRect = "myRect";
string myRect2 = "myRect";
int mystartBarCounter = 4;
//int myHighLowCounter = 8;
bool swingHigh = High[6] <= High[3] && High[5] <= High[3] && High[4] < High[3] && High[2] <= High[3] && High[1] <= High[3] && High[0] <= High[3];
//if 3rd bar in 7 has 3 lower highs to the right and left, draw a rectangle from swing highest high to swing highest close
if(swingHigh)
{
mystartBar = CurrentBar - 4; // pick a startpoint
rect_high = MAX(High,8)[0]; // pick a high level
rect_low = MIN(Low,8)[0]; // pick a low level
rect_close1 = MAX(Close,8)[0]; // pick a close for highest bar level
rect_close2 = MIN(Close,8)[0]; // pick a close for lowest bar level
if(DoItOnce)
{
Draw.Rectangle(this, CurrentBar.ToString() + "myRect", false, 3, rect_close1, 0, rect_high, Brushes.DarkRed, Brushes.Red, 5, false);
DoItOnce = false;
}
}
else if(keepDrawing)
{
Draw.Rectangle(this, CurrentBar.ToString() + "myRect", false, 3, rect_close1, 0, rect_high, Brushes.DarkRed, Brushes.Red, 5, false);
}
else if(HighestBar(Close, 1) > HighestBar(High, mystartBar))
{
keepDrawing = false;
}

Comment