Problem with many rectangles

 

Hi guys, I have a problem with rectangles...

I have a for loop with which I draw many rectangles on the chart,(15/20), and agni new candle I want to update the anchor point and not a problem this.
But I notice that the indicator fails to update all rectangles making a lot of confusion in the chart.


if( ObjectFind(0,"GapSell"+IntegerToString(s)) == -1)
                  {
                     Print(s);
                     Rettangolo("GapSell"+IntegerToString(s),ColoreDX,time1,Price1,time2,Price2);
                  }

                  else if(ObjectFind(0,"GapSell"+IntegerToString(s)) != -1)
                  {

                     //if(ObjectMove(0,"GapSell"+IntegerToString(s),1,time2,Price2)) Print("s: ",s," Move", "Time: ",TimeToString(time2));                     
                     //ObjectSetInteger(0,"GapSell"+IntegerToString(s),OBJPROP_TIME2,tempo);
                     
                     ObjectDelete(0,"GapSell"+IntegerToString(s));                     
                     //Rettangolo("GapSell"+IntegerToString(s),ColoreDX,time1,Price1,time2,Price2);

                  }

I've tried different solutions by deleting the rectangle and rewriting it or moving it or changing the time setting..
it all works at the code level manel graph it's like the MT4/MT5 can't handle all these drawings to do.

How can I solve it?

 

Well, I use this within my functions to create new Objects:

string nme = "...";
if(ObjectFind(0,nme) >= 0) ObjectDelete(0,nme); ResetLastError(); // delete existing object.
...

Read the ref. for ObjectFind(): place the cursor in the MQ editor on the function and press F1:

If the object is not found, the function returns a negative number. To read more about the error call GetLastError().

"a negative number" - not necessarily -1.

Documentation on MQL5: Object Functions / ObjectFind
Documentation on MQL5: Object Functions / ObjectFind
  • www.mql5.com
ObjectFind - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

I also used < 0

if( ObjectFind(0,"GapSell"+IntegerToString(s)) < 0)

The real problem, however, is not the code but the MT4/5 makes it difficult to handle so many objects in the graph because they are asynchronous functions

 
fly7680:

Hi guys, I have a problem with rectangles...

I have a for loop with which I draw many rectangles on the chart,(15/20), and agni new candle I want to update the anchor point and not a problem this.


How can I solve it?

15/20 rectangles? It's not a lot

 
fly7680: I have a problem with rectangles...
  1. Don't keep coping code.
    if( ObjectFind(0,"GapSell"+IntegerToString(s)) == -1){
       Rettangolo("GapSell"+IntegerToString(s),ColoreDX,time1,Price1,time2,Price2);
    Write it once, so it's readable and understandable.
    string name = "GapSell"+IntegerToString(s);
    if( ObjectFind(0,name) == -1){
       Rettangolo(name,ColoreDX,time1,Price1,time2,Price2);
    
  2. What is "s"? Use readable, understandable variable names. It can't be an as-series index, as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g., “name0”), same, existing, previous, name (e.g., “name0” now on bar one.)

    Use time (as int) or a non-series index:

    #define  SERIES(I)   (Bars - 1 - I) // As-series to non-series or back.
 
William Roeder #:
  1. Don't keep coping code.
    Write it once, so it's readable and understandable.
  2. What is "s"? Use readable, understandable variable names. It can't be an as-series index, as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g., “name0”), same, existing, previous, name (e.g., “name0” now on bar one.)

    Use time (as int) or a non-series index:


int s; it's a simple variable to increment the number on the name rectangles... I'll do some tests based on what you wrote! Thanks William Roeder