Download MetaTrader 5

Object overlapping color problem

To add comments, please log in or register
Mimi
501
Mimi  

Hi I have seen If two object crossed with each other then the cross section get white or in other color. Is there any way to avoid that?

 

I don't want the white area, I want it to be full blue.

How can I do that? One thing predicting object cross section are is not possible as its dynamic.

Regards

Mimi
501
Mimi  
i used following code for Rectangles & Triangles.
      ObjectSet(Obj_Name,OBJPROP_COLOR, Blue);      
Mimi
501
Mimi  

I tried using this function:

color MaskColour(color back, color front, color chartBackground) {
   back ^= front;
   back ^= chartBackground;
   return back;
}

 

ObjectSet(Obj_Name,OBJPROP_COLOR,MaskColour(ChartBackgroundCol,Blue,ChartBackgroundCol)); 

 But the result is pretty much same.

Alain Verleyen
Moderator
31185
Alain Verleyen  
That's not possible with 2 objects RECTANGLE, you need to use a bitmap and draw the rectangle yourself or eventually a third rectangle.
Mimi
501
Mimi  
angevoyageur:
That's not possible with 2 objects RECTANGLE, you need to use a bitmap and draw the rectangle yourself or eventually a third rectangle.

Any coding example for Mql4, I can not predict the overlapping area, So can not draw 3rd rectangle. 

Mimi
501
Mimi  

Ok Bitmap image on chart I got it. I hope I can 2 price & time anchor point.

But by changing  ENUM_COLOR_FORMAT does it going to work for basic Mql4 objects? 

Mimi
501
Mimi  

I tried using following simple code to work with bitmap files.

But its showing an error "Implicit conversion from string to number". Plus not showing any picture on chart.

#property indicator_chart_window
#resource "\\Images\\Box.bmp" 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
input string          InpFile="\\Images\\Box.bmp"; // Bitmap file name
input bool            InpBack=false;                  // Background object
input bool            InpSelection=false;             // Highlight to move
input bool            InpHidden=true;                 // Hidden in the object list

int start()
{
ObjectCreate(0,"Box",OBJ_BITMAP,0,TimeCurrent(),0);
ObjectSet("Box",OBJPROP_BMPFILE,InpFile); // error here
ObjectSet("Box",OBJPROP_COLOR,Red);
ObjectSet("Box",OBJPROP_BACK,InpBack);
ObjectSet("Box",OBJPROP_XDISTANCE,10);
ObjectSet("Box",OBJPROP_YDISTANCE,10);


return(0);
}
Alain Verleyen
Moderator
31185
Alain Verleyen  
cashcube:

I tried using following simple code to work with bitmap files.

But its showing an error "Implicit conversion from string to number". Plus not showing any picture on chart.

 

You can't use ObjectSet() for OBJPROP_BMPFILE, you need to use ObjectSetString().

You would have known it by checking the return value of ObjectSet() :

If the function succeeds, the returned value will be true, otherwise it returns false. To get the detailed error information, one has to call the GetLastError() function.

Mimi
501
Mimi  
angevoyageur:

You can't use ObjectSet() for OBJPROP_BMPFILE, you need to use ObjectSetString().

You would have known it by checking the return value of ObjectSet() :

Hi Thank you for correcting. But I changed thing its still not working showing 4200 error,  Object already exists.

#resource "\\Images\\Box.bmp" 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
input string          InpFile="\\Images\\Box.bmp"; // Bitmap file name
input bool            InpBack=false;                  // Background object
input bool            InpSelection=false;             // Highlight to move
input bool            InpHidden=true;                 // Hidden in the object list

int start()
{
//string B = StringConcatenate("UpArrow",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS ));
if(!ObjectCreate(0,"Box",OBJ_BITMAP,0,0,0))
printf(IntegerToString(GetLastError()));
ObjectSetString(0,"Box",OBJPROP_BMPFILE,0,InpFile);
ObjectSet("Box",OBJPROP_COLOR,Red);
//ObjectSet("Box",OBJPROP_BACK,InpBack);
ObjectSet("Box",OBJPROP_XDISTANCE,10);
ObjectSet("Box",OBJPROP_YDISTANCE,10);
ObjectSet("Box",OBJPROP_XSIZE,100);
ObjectSet("Box",OBJPROP_YSIZE,100);
ObjectSetInteger(0,"Box",OBJPROP_XOFFSET,0);
ObjectSetInteger(0,"Box",OBJPROP_YOFFSET,0);
ObjectSetInteger(0,"Box",OBJPROP_WIDTH,1);

return(0);
}





 Even if I use that StringConcatenate line still same problem.

Fernando Carreiro
2279
Fernando Carreiro  

Let us think logically:

  1. It is in an Indicator and therefore the "start()" event handler gets called on every tick.
  2. On the first tick, you create an Chart Object called "Box" (and all works well, if its the first time you run your code on the chart)
  3. On the second and subsequent ticks, yet again you try to create the Chart Object called "Box", but it is was already created on the FIRST tick!!!!

Do you see the problem? Do you see WHY you get Error 4200 (Object already exists)?

So, to fix the problem:

  1. Before creating the Chart Object, check to see if it does not already exist, by using the function "ObjectFind()" and then only adjust its properties.
  2. Before terminating the Indicator, delete the object in the "deinit()" event handler by using the function "ObjectDelete()", otherwise the next time you run the indicator it will fail because the Chart Object is already there.

NB! Consider using the modern style of MQL4+ coding and using "OnCalculate()" instead of "start()", "OnDeinit()" instead of "deinit()", etc.

Mimi
501
Mimi  
FMIC:

Let us think logically:

  1. It is in an Indicator and therefore the "start()" event handler gets called on every tick.
  2. On the first tick, you create an Chart Object called "Box" (and all works well, if its the first time you run your code on the chart)
  3. On the second and subsequent ticks, yet again you try to create the Chart Object called "Box", but it is was already created on the FIRST tick!!!!

Do you see the problem? Do you see WHY you get Error 4200 (Object already exists)?

So, to fix the problem:

  1. Before creating the Chart Object, check to see if it does not already exist, by using the function "ObjectFind()" and then only adjust its properties.
  2. Before terminating the Indicator, delete the object in the "deinit()" event handler by using the function "ObjectDelete()", otherwise the next time you run the indicator it will fail because the Chart Object is already there.

NB! Consider using the modern style of MQL4+ coding and using "OnCalculate()" instead of "start()", "OnDeinit()" instead of "deinit()", etc.

Hi Thank you for the detail description about the problem & Solution.

I added it as you recommend. But now its shows unknown object property error: 4201

int start()
{

if(ObjectFind(0,"Box")<0) // If there is no object in the chart.
{
ObjectCreate(0,"Box",OBJ_BITMAP,0,0,0); // now create object
ObjectSetString(0,"Box",OBJPROP_BMPFILE,0,InpFile);
ObjectSetInteger(0,"Box",OBJPROP_XSIZE,100);
ObjectSetInteger(0,"Box",OBJPROP_YSIZE,100);
ObjectSet("Box",OBJPROP_COLOR,Red);
ObjectSet("Box",OBJPROP_BACK,InpBack);
ObjectSet("Box",OBJPROP_XDISTANCE,10);
ObjectSet("Box",OBJPROP_YDISTANCE,10);
ObjectSetInteger(0,"Box",OBJPROP_XOFFSET,0);
ObjectSetInteger(0,"Box",OBJPROP_YOFFSET,0);
ObjectSetInteger(0,"Box",OBJPROP_WIDTH,1);
ObjectSetInteger(0,"Box",OBJPROP_STYLE,1);
printf(IntegerToString(GetLastError()));
}

return(0);
}
//--------------------------------------------------------
int deinit()
{
      ObjectDelete("Box"); 

return(0);
}

I will add onCalculate later when this code will start working.

Regards

12
To add comments, please log in or register