How to Draw S/R Lines and Block? - page 2

 
GumRai:

I suggest that you look in the Objects list and you will see it there. Maybe it has been drawn off screen


Hello,

Thanks explaining the suggestion.

I checked the properties and found the object of rectangular. Then I zoomed out the chart and found the Rectangle!

But still the Expert tab is showing the error.

Another thing is I'm trying to draw multiple rectangles using external output for price. So I tried this:

extern double Price_H_1=1.68505
extern double Price_L_1=1.68405
extern double Price_H_2=1.68305
extern double Price_L_2=1.68205

{
//--- reset the error value
   ResetLastError();

   string name="New_Rectangualr_object";
   
 bool   first_rec= ObjectCreate(name,OBJ_RECTANGLE,0, Time[10000],Price_L_1, Time[0],Price_H_1, 0, 0);
   if(!first_rec)
     {
      Print("Error: failed to create First rectangle! Error code:",GetLastError());
      return(0);
     }
    ObjectSet(name,OBJPROP_COLOR,Blue);  
  
 bool second_rec=  ObjectCreate(name,OBJ_RECTANGLE,0, Time[10000],Price_L_2, Time[0],Price_H_2, 0, 0);
   if(!second_rec)
     {
      Print("Error: failed to create Second rectangle! Error code:",GetLastError());
      return(0);
     }
   ObjectSet(name,OBJPROP_COLOR,Red);
  } 

But there is no more rectangle in the chart and the properties. So what mistake I have done here or

how to create multiple rectangle?

Regards

 
You should have learned from previous replies that you cannot create a new object with the same name as an existing one.
 
The error code usually means that the object already drawn. So, just to make sure, insert code to delete the object onDeInit function. Also have a check if the object existed or not, by using object find function.
 
GumRai:
You should have learned from previous replies that you cannot create a new object with the same name as an existing one.


ohh, Yes, I forgot that.

But after changing like this still it's not appearing.

{
//--- reset the error value
   ResetLastError();

   string name="New_Rectangualr_object";
   string name_2="Second_Rectangualr_object";
   //long chart_ID=ChartID();
   
 bool   first_rec= ObjectCreate(name,OBJ_RECTANGLE,0, Time[10000], 1.68405, Time[0], 1.68505, 0, 0);
   if(!first_rec)
     {
      Print("Error: failed to create First rectangle! Error code:",GetLastError());
      return(0);
     }
    ObjectSet(name,OBJPROP_COLOR,Blue);   
     
 bool second_rec=  ObjectCreate(name_2,OBJ_RECTANGLE,0, Time[10000],1.68205, Time[0],1.68305, 0, 0);
   if(!second_rec)
     {
      Print("Error: failed to create Second rectangle! Error code:",GetLastError());
      return(0);
     }
   ObjectSet(name_2,OBJPROP_COLOR,Red);
  }

Actually, the second function isn't getting executed at all as I'm getting error message for the first one only:

Regards

 
I am sorry to ask but have you check what error code 4200 means ? Just to be sure.
 
deysmacro:
I am sorry to ask but do you know what error code 4200 means ? Just to be sure.


Yes.

It means Object already exists.

 
I think I know what is the problem because I also have the same problem last time. Unfortunately, it is becoming more advanced for a simple help.
 
deysmacro:
I think I know what is the problem because I also have the same problem last time. Unfortunately, it is becoming more advanced for a simple help.


It's OK but can you please show how to draw multiple rectangles simultaneously disregarding the error?

 
Try using loop. There is a way of drawing multiple rectangles or other objects using loop.
 
deysmacro:
Try using loop. There is a way of drawing multiple rectangles or other objects using loop.


Not understanding how to use Loop here.

Tried a bit:

{
//--- reset the error value
   ResetLastError();

   int count=0;
for(int i=0; i<2;i++)
{
if(count==0)
{  
name="New_Rectangualr_object"; 
double price1=1.68405;
double price2=1.68505;
}
if(count==1)
{  
name="Sed_Rectangualr_object"; 
price1=1.68205;
price2=1.68305;
}
bool first_rec= ObjectCreate(name,OBJ_RECTANGLE,0, Time[10000], price1, Time[0], price2, 0, 0);
   if(!first_rec)
     {
      Print("Error: failed to create rectangle! Error code:",GetLastError());
      return(0);
     }
     else
     {
     count=count+1;
     }
    ObjectSet(name,OBJPROP_COLOR,Blue);  
    Print("Count:",count); 
   }
  } 

But not working.