I want to draw a rectangle across the candles when envelope of the bodies of three consecutive candles less than 10 ticks and I've written the following scripts to perform this:
[I]protected override void Initialize()
{
CalculateOnBarClose= false; Overlay= true;
}
protected override void OnBarUpdate()
{
rangeTop = Math.Max(MAX(Close,3)[0],MAX(Open,3)[0]);
rangeBot = Math.Min(MIN(Close,3)[0],MIN(Open,3)[0]);
if (rangeTop-rangeBot<=10 * TickSize)
{
DrawRectangle("narrow range"+ CurrentBar, false, 3, rangeBot, -1,
rangeTop,Color.Transparent,Color.Silver,8);
}
else if (rangeTop-rangeBot>10 * TickSize)
{RemoveDrawObject("narrow range");}
Silver rectangles appear on the screen correctly. However, when the body of the third candle moves beyond the 10-tick limit the rectangle just stops with 10 ticks height and remains there. My intention is to have it removed.
Can anybody kindly offer some assistance on the above. Thanks.
Comment