Hi
Yes, but you need to code a script (EA or indicator) for it you can create a simple button and then code the function which will manage pressing this button.
For example, make the EA with function in OnInit:
long cId = ChartID(); name = “white”; if(ObjectFind(cId, name)<0){ ObjectCreate(cId, name, OBJ_BUTTON, 0,0,0); ObjectSetString(cId, name, OBJPROP_TEXT, “CREATE RECTANGLE”); ObjectSetInteger(cId, name,OBJPROP_FONTSIZE, 10); ObjectSetInteger(cId, name, OBJPROP_COLOR, clrWhite); ObjectSetInteger(cId, name, OBJPROP_BGCOLOR, clrBlue); ObjectSetInteger(cId, name,OBJPROP_BACK,false); ObjectSetInteger(cId, name, OBJPROP_STATE, false); ObjectSetInteger(cId,name,OBJPROP_CORNER, CORNER_LEFT_UPPER); ObjectSetInteger(cId,name,OBJPROP_XDISTANCE, 5); ObjectSetInteger(cId,name,OBJPROP_YDISTANCE, 20); ObjectSetInteger(cId, name, OBJPROP_XSIZE, 50); ObjectSetInteger(cId, name, OBJPROP_YSIZE, 20); } And then in the OnChartEven function add this: if (id==CHARTEVENT_OBJECT_CLICK) { if (sparam==”white”) { drawRectangle(clrWhite); } } void drawRectangle(color clr){ name = “Rectangle”; long cId = ChartID(); //you can set here initial times and prices for rectangle datetime t1 = Time[1]; datetime t2 = Time[10]; double p1 = Open[1]; double p2 = Open[10] ; if(ObjectFind(cId, name)<0){ ObjectCreate(cId, name, OBJ_RECTANGLE, 0, t1, p1, t2, p2); ObjectSetInteger(cId, name, OBJPROP_COLOR, clr); ObjectSetInteger(cId, name, OBJPROP_WIDTH, 1); ObjectSetInteger(cId, name, OBJPROP_BACK, true); ObjectSetInteger(cId, name, OBJPROP_FILL, true); } }
Best Regards
Hi
Yes, but you need to code a script (EA or indicator) for it you can create a simple button and then code the function which will manage pressing this button.
For example, make the EA with function in OnInit:
Best Regards
Thank's, but this way it directly draw it on chart. I would like to have it "on my hands", like this when you press the rectangle symbol on MT4 tool bar and your cursor have a little rectangle indicating that it will spawn a rectangle where you will click on the chart.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello. Is it possible to create a button that when pressed behave like when you press the "draw rectangle" button but it gives you a rectangle of a certain color?
Like create a button called "white" rectangle and when you press it then you can draw a white rectangle with your cursor, without having to draw the rectangle and then right click and change color to white.
Thank's.