Problem with Object ?

 

Hi,

I have muliples weird things while I try to create 2 simples Rectangles object:

Both are created fine when I attach EA to the chart but:

1 ) When EA tries to create again and again the first one rectangle (Support) so I got error 4200 (Object already exist): with the print function.

2 ) CTRL+B I deleted both rectangles then EA re creates both rectangles but the previous error still happens 

3 ) If I delete Support rectangle... EA will re create the object while If I delete Resistance Rectangle EA won't re create it.... It will only if both are missing. So it means that the problem may come from in fact from the second object.

4 ) Even If I use Objectdelete() function into desinitialisation... when I take it of the EA, both object stay on chart?

5 ) Also i notice that the Print function only works when it draws Rectangles on chart.... that could explain why Global var aren't updated...


=> My goal is to create 2 rectangles that I could manually adjust time by time and EA will reacts from those price level. So I created Global Variables but even if I modify manually the rectangles, Global Var aren't updated?


//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
    GlobalVariableDel("GV_S_time1");     GlobalVariableDel("GV_S_time2");
    GlobalVariableDel("GV_R_time1");     GlobalVariableDel("GV_R_time2");
    GlobalVariableDel("GV_S_Price1");     GlobalVariableDel("GV_S_Price2");
    GlobalVariableDel("GV_R_Price1");     GlobalVariableDel("GV_R_Price2");
    
    GlobalVariableDel("Resistance");     GlobalVariableDel("Support");
        

  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
  //-----------------------------------------------------------------
//   DESIGN SUPPORT & RESISTANCE
//-----------------------------------------------------------------    
   
      
    string name_rect = "Support";
    double S_Candle_High = iHigh(NULL,PERIOD_H1,10); double S_Candle_Low = iLow(NULL,PERIOD_H1,10);
    

    bool Support_Rectangle =    ObjectCreate(name_rect,OBJ_RECTANGLE,0,Time[15],S_Candle_High,TimeCurrent(),S_Candle_Low,0,0);
    if (!Support_Rectangle) {  Print("Failed to create Rectangle_Support. Error code= ",GetLastError() );
    return(0);}
    ObjectSet(name_rect,OBJPROP_COLOR,LightGreen);
   
   // GEt data
    datetime S_time1 = ObjectGetInteger(0,"Support",OBJPROP_TIME1,0);
    double S_Price1 = ObjectGet("Support",OBJPROP_PRICE1);
    datetime S_time2 = ObjectGetInteger(0,"Support",OBJPROP_TIME2,0);
    double S_Price2 = ObjectGet("Support",OBJPROP_PRICE2);
    
    if (S_time1<S_time2) {datetime Var_S_Time1=S_time1; datetime  Var_S_Time2=S_time2;} else {Var_S_Time1=S_time2; Var_S_Time2=S_time1; }
      if (S_Price1<S_Price2) {double Var_S_Price1=S_Price1; double  Var_S_Price2=S_Price2;} else {Var_S_Price1=S_Price2; Var_S_Price2=S_Price1; }
      
   
    Print("Support: time1=",Var_S_Time1," Price1=",Var_S_Price1," time2=",Var_S_Time2," Price2=",Var_S_Price2);  
   
    
    
    
    string name_rect_1 = "Resistance";
    double R_Candle_High = iHigh(NULL,PERIOD_H1,10); double R_Candle_Low = iLow(NULL,PERIOD_H1,10);
    

    bool Resistance_Rectangle =    ObjectCreate(name_rect_1,OBJ_RECTANGLE,0,Time[15],R_Candle_High,TimeCurrent(),R_Candle_Low,0,0);
    if (!Resistance_Rectangle) {  Print("Failed to create Rectangle_Support. Error code= ",GetLastError() );
    return(0);}
    ObjectSet(name_rect_1,OBJPROP_COLOR,Coral);
   
   // GEt data
    datetime R_time1 = ObjectGetInteger(0,"Resistance",OBJPROP_TIME1,0);
    double R_Price1 = ObjectGet("Resistance",OBJPROP_PRICE1);
    datetime R_time2 = ObjectGetInteger(0,"Resistance",OBJPROP_TIME2,0);
    double R_Price2 = ObjectGet("Resistance",OBJPROP_PRICE2);
    
     if (R_time1<R_time2) {datetime Var_R_Time1=R_time1; datetime  Var_R_Time2=R_time2;} else {Var_R_Time1=R_time2; Var_R_Time2=R_time1; }
      if (R_Price1<R_Price2) {double Var_R_Price1=R_Price1; double  Var_R_Price2=R_Price2;} else {Var_R_Price1=R_Price2; Var_R_Price2=R_Price1; }
    

    
    Print("Resistance: time1=",Var_R_Time1," Price1=",Var_R_Price1," time2=",Var_R_Time2," Price2=",Var_R_Price2);  
    /////////////////////////////////////////////////////////////////////////////////////////////////////




// PLEASE HELP  : )
 
  
    string name_rect = "Support";
    double S_Candle_High = iHigh(NULL,PERIOD_H1,10); double S_Candle_Low = iLow(NULL,PERIOD_H1,10);
    

    bool Support_Rectangle =    ObjectCreate(name_rect,OBJ_RECTANGLE,0,Time[15],S_Candle_High,TimeCurrent(),S_Candle_Low,0,0);
    if (!Support_Rectangle) {  Print("Failed to create Rectangle_Support. Error code= ",GetLastError() );
    return(0);}

If you indented your code, it would be much easier to read and find errors. Not only for us, but for you as well.

If the first object exists, then start() would only run as far as the return(0), so whether the 2nd object exists or not, the code to create it will not be executed. 

Create the objects in init. 

 
GumRai:

If you indented your code, it would be much easier to read and find errors. Not only for us, but for you as well.

If the first object exists, then start() would only run as far as the return(0), so whether the 2nd object exists or not, the code to create it will not be executed. 

Create the objects in init. 


Hi,


Thank you for your help.... Ps. I did not intend code... I simply  forgot to add global variable part.

I wasn't aware of the return(0) function was stopping the EA to run. So I put this line into comment "//..." and now it works fine.

I created the name of rectangle ading "_Symbol" to get 2 rectangles names per chart.

When I do CTRL+B when EA creates an pending orders... It adds 3 objects called Arrow (Pending price, SL, TP)...

Is there any way to cancel thoses objects, so it only contains my rectangles? ---> I know I can delete them but I would like it won't get messy all time

 
FrenchyTrader:

Hi,


Thank you for your help.... Ps. I did not intend code... I simply  forgot to add global variable part.

I wasn't aware of the return(0) function was stopping the EA to run. So I put this line into comment "//..." and now it works fine.

I created the name of rectangle ading "_Symbol" to get 2 rectangles names per chart.

When I do CTRL+B when EA creates an pending orders... It adds 3 objects called Arrow (Pending price, SL, TP)...

Is there any way to cancel thoses objects, so it only contains my rectangles? ---> I know I can delete them but I would like it won't get messy all time


You don't seem to understand what indented code is.

This is an absolute mess

    if (S_time1<S_time2) {datetime Var_S_Time1=S_time1; datetime  Var_S_Time2=S_time2;} else {Var_S_Time1=S_time2; Var_S_Time2=S_time1; }
      if (S_Price1<S_Price2) {double Var_S_Price1=S_Price1; double  Var_S_Price2=S_Price2;} else {Var_S_Price1=S_Price2; Var_S_Price2=S_Price1; }
      
   
    Print("Support: time1=",Var_S_Time1," Price1=",Var_S_Price1," time2=",Var_S_Time2," Price2=",Var_S_Price2);  
   
    

 This is much easier to follow

    if (S_time1<S_time2) 
       {
       datetime Var_S_Time1=S_time1; 
       datetime  Var_S_Time2=S_time2;
       } 
    else
       {
       Var_S_Time1=S_time2; 
       Var_S_Time2=S_time1; 
       }
    if (S_Price1<S_Price2)
       {
       double Var_S_Price1=S_Price1; 
       double  Var_S_Price2=S_Price2;
       } 
    else 
       {
       Var_S_Price1=S_Price2; 
       Var_S_Price2=S_Price1; 
       }
    Print("Support: time1=",Var_S_Time1," Price1=",Var_S_Price1," time2=",Var_S_Time2," Price2=",Var_S_Price2);  

 

 If you post messy undisciplined code, you are less likely to find anyone to help you.

 
GumRai:


You don't seem to understand what indented code is.

This is an absolute mess

 This is much easier to follow

 

 If you post messy undisciplined code, you are less likely to find anyone to help you.

 

 Humm Ok I got it now : )


Any clue about this?


When I do CTRL+B to check objects, whenever EA creates a pending orders... It adds 3 objects called Arrow (Pending Price, SL, TP)... Could we disable those objects creation.

 
FrenchyTrader:

 Humm Ok I got it now : )


Any clue about this?


When I do CTRL+B to check objects, whenever EA creates a pending orders... It adds 3 objects called Arrow (Pending Price, SL, TP)... Could we disable those objects creation.



Using Ctrl F, I can only find 2 ObjectCreate() in your posted code and they are both rectangles.

 Find the ObjectCreate's that paint the arrows and remove the code that creates them along with any related ObjectSet code.

Reason: