Pouring the object

 

Greetings, dear programmers!

"For MT4 terminal.

I would like to get some tips from you. I have come across the following nuance...

1. I create a rectangle object - it works:

2. I set the properties:

- style - it worked;

- line width - worked;

- colour - worked;

- fill - doesn't want to listen;

I messed around and messed around and found out that the rectangle object is created with "Draw object as background" checked by default. As long as this checkbox is checked, the rectangle does not listen to commands from the program, and if you manually remove this checkbox from the properties of the object, then the program can control the fill.

The question is why the object is not set to "fill" property right away? What I do wrong and what I do not know?

Please help who can!

Below is the used code:

#property indicator_chart_window

int start()
{
long current_chart_id=ChartID();
//
string obj_name1="Rectangle1";
//
double Price_Level_1 = 1296; // gold price
double Price_Level_2 = 1293;
//
datetime Left_Side_1 = Time[9];
// datetime Right_Side_1 = Time[0] + PeriodSeconds() * 7;
//
const color clr = clrBeige;
const ENUM_LINE_STYLE style = STYLE_DASH;
const int width = 1;
const bool fill = false;
//
ObjectCreate (current_chart_id, obj_name1, OBJ_RECTANGLE, 0, Left_Side_1, Price_Level_1, Right_Side_1, Price_Level_2);
ObjectSetInteger (current_chart_id, obj_name1, OBJPROP_COLOR, clr);
ObjectSetInteger (current_chart_id, obj_name1, OBJPROP_STYLE, style);
ObjectSetInteger (current_chart_id, obj_name1, OBJPROP_WIDTH, width);
ObjectSetInteger (current_chart_id, obj_name1, OBJPROP_FILL, false); // not set immediately

return(0);

 

Try

//+------------------------------------------------------------------+
void Prn_Rect_Label(string Name, int X, int Y, int width, int height, color CLR, int Corner, bool back)
   {
      ObjectDelete(0,Name);
      ObjectCreate(0,Name,OBJ_RECTANGLE_LABEL,0,0,0);
      ObjectSetInteger(0,Name,OBJPROP_XDISTANCE,X);
      ObjectSetInteger(0,Name,OBJPROP_YDISTANCE,Y);
      ObjectSetInteger(0,Name,OBJPROP_XSIZE,width);
      ObjectSetInteger(0,Name,OBJPROP_YSIZE,height);
      ObjectSetInteger(0,Name,OBJPROP_BGCOLOR,CLR);
      ObjectSetInteger(0,Name,OBJPROP_CORNER,Corner);
      ObjectSetInteger(0,Name,OBJPROP_BACK,back);
      return;
   }
 
What's the trick? Why doesn't the object respond to the fill without further manipulation?
 
Renat Akhtyamov:

Try

You don't have to delete it, you have to check it to see if it exists. If it doesn't exist, then create it. And then set the parameters.
 
So, why isn't the filler listening?
 
Artyom Trishkin:
You don't have to delete it, you have to check it to see if it exists. If it doesn't exist, then create it. And then set parameters.

Agreed

find first.

But if the object is deleted and re-created on every tick with the same name, searching for a known-existing object is unnecessary
 
5211845:
So, why is the fill not listening?

and if so (false --> true):

   ObjectSetInteger (current_chart_id, obj_name1, OBJPROP_FILL, true); // не задается сразу
 

It doesn't work. I've already tried the following function

ObjectSet (obj_name1, OBJPROP_FILL, true | false);

 
Does this code have to work at all? Maybe it's a glitch in my terminal?

ObjectSetInteger (current_chart_id, obj_name1, OBJPROP_FILL, false);

 
5211845:
In general, this code should work? Maybe it's a glitch in my terminal?

ObjectSetInteger (current_chart_id, obj_name1, OBJPROP_FILL, false);

Of course.

Compare this code with your own code in details and place it in OnTimer(), as there are no output ticks, or temporarily run it in OnInit():

https://www.mql5.com/ru/docs/constants/objectconstants/enum_object/obj_rectangle

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Типы объектов / OBJ_RECTANGLE
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Типы объектов / OBJ_RECTANGLE
  • www.mql5.com
//| Cоздает прямоугольник по заданным координатам                    |               time1=0,                            price1=0,                         time2=0,                            price2=0,                        width=1,            //| Перемещает точку привязки прямоугольника                         |...
 

I based my code on this example. I just can't figure out what the difference is. Only that there is a window for input parameters.

What if I don't need this window? If I just want to create an object with the parameters I want. Is this possible?

Reason: