Contribution: drawing rectangles on charts

 

Hi everyone

As we know there are some requests about drawing rectangles on charts or just to make our custom indicators more "beautiful". By this I have made a function that can be used to do this kind of thing. Just give me credits for it if you use it, that's all I ask. So you probably asking how it works, for sure this is not the best way but for now is the way I can do, it gets the character 110(the square) from the font wingdings and draw 1, 2, 3...anyway how much it needs to make the cell, but don't worry the function is made to calculate how much squares are needed to don't be too heavy to draw. I hope soon metaquotes let us draw rectangles without making things like these.

To use it is simple:

nWindow = The window that will be used to draw.

nCellName = The base name for the cell(it's a base name so if it needs to draw 2 or more squares the names will be like "basename1", "basename2"...

nX = The top corner X position.

nY = The top corner Y position.

nWidth = Width of the cell.

nHeight = Height of the cell.

nColor = Color.

//=========================================================

// DrawCell.

//

// Author: Alexandre A. B. Borela

// Description: Draws a cell using the minimum character

// as it can, so it's going to take less time

// to draw the cell.

void DrawCell(int nWindow, string nCellName, double nX, double nY, double nWidth, double nHeight, color nColor)

{

double iHeight, iWidth, iXSpace;

int iSquares, i;

if(nWidth > nHeight)

{

iSquares = MathCeil(nWidth/nHeight); // Number of squares used.

iHeight = MathRound((nHeight*100)/77); // Real height size.

iWidth = MathRound((nWidth*100)/77); // Real width size.

iXSpace = iWidth/iSquares - ((iHeight/(9-(nHeight/100)))*2);

for(i=0;i<iSquares;i++)

{

ObjectCreate (nCellName+i, OBJ_LABEL,nWindow,0,0);

ObjectSetText (nCellName+i, CharToStr(110),iHeight, "Wingdings", nColor);

ObjectSet (nCellName+i, OBJPROP_XDISTANCE,nX + iXSpace*i);

ObjectSet (nCellName+i, OBJPROP_YDISTANCE,nY);

ObjectSet (nCellName+i, OBJPROP_BACK, true);

}

}else{

iSquares = MathCeil(nHeight/nWidth); // Number of squares used.

iHeight = MathRound((nHeight*100)/77); // Real height size.

iWidth = MathRound((nWidth*100)/77); // Real width size.

iXSpace = iHeight/iSquares - ((iWidth/(9-(nWidth/100)))*2);

for(i=0;i<iSquares;i++)

{

ObjectCreate (nCellName+i, OBJ_LABEL,nWindow,0,0);

ObjectSetText (nCellName+i, CharToStr(110),iWidth, "Wingdings", nColor);

ObjectSet (nCellName+i, OBJPROP_XDISTANCE,nX);

ObjectSet (nCellName+i, OBJPROP_YDISTANCE,nY + iXSpace*i);

ObjectSet (nCellName+i, OBJPROP_BACK, true);

}

}

}

An example of use:

int start()

{

ObjectsDeleteAll(0);

DrawCell(0,"test",200,200,20,100,White);

return(0);

}

I hope this will improve the way we see those signal tables to make it even better, an example of my signal table using this feature:

Files:
example.jpg  194 kb
 

Thanks for the contribution!

Nice looking indicator. Is that available somewhere?

Thanks,

Mark.

 

That was made by me and it's not available yet, for now I'm just dealing with the function that generate those signals because it calculate over a lot of bars to generate a signal for each time frame, this make some lags as you may imagine, as soon as I make it better I'll post here.

Reason: