Download MetaTrader 5

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

To add comments, please log in or register
Added support for the Spanish language. Come and check it out!
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.06 13:39  

Actually when using loop, you are making the name becomes unique.

Example: name+i

i is the key factor to make the name unique.

Keith Watford
Moderator
9644
Keith Watford 2014.05.06 13:42  
Arav007:


ohh, Yes, I forgot that.

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

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

Regards


When you want people to help you, you have to pay attention to their advice and implement it.

You are doing nothing in your code to delete an object with the same name or check whether the object exists already.

{
//--- 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);
  }

It is quite obvious that you ran this code to create the first object, then added code to create the 2nd.

Because the first object already exists, you get the error and then return(0)

So the code for the 2nd object will not be implemented.

Arav007
412
Arav007 2014.05.06 13:43  
deysmacro:

Actually when using loop, you are making the name becomes unique.

Example: name+i

i is the key factor to make the name unique.


But I have to provide different prices too.

Also how can I add string with integer in 'name+i'?

Arav007
412
Arav007 2014.05.06 17:32  
GumRai:


When you want people to help you, you have to pay attention to their advice and implement it.

You are doing nothing in your code to delete an object with the same name or check whether the object exists already.

It is quite obvious that you ran this code to create the first object, then added code to create the 2nd.

Because the first object already exists, you get the error and then return(0)

So the code for the 2nd object will not be implemented.


Hello,

I always pay attention to the advice but I'm not that much sound in coding yet thus I can understand the Hints without a bit of explanation.

That's why I might miss them, Sorry.

ohh ohh ohh, just a possible reason for the error has come across my mind during replying!

I guess the 'Error' message is showing again and again because on the 'First' run, the EA is creating a 'Rectangle' on the chart.

Then on the second Tick (run), it's going through the same piece of code again and finding that an 'Object' is already Existing with the

same 'Object Name'. So it's not creating the Object again instead showing the Error message, right?

And to get rid of this, you suggested to check First if there is already an Object existing with the same name or not?

If yes, then 'Delete' it first and then Create a New One. Thus the same rectangle will be on the chart but it'll keep deleting and reforming

so that it'll seem that a Rectangle is always there.

As the EA is failing to create a New Rectangle and getting error, it's not proceeding to the next part (to create Second rectangle).

I might be wrong.

But if my concept is right, then another question arises.

That is, if the EA is getting this Error on the Second Tick after creating the Rectangle on the very First Tick already, then why not it's

creating the Second rectangle on the First Tick too? As it's not getting the Error on the Very First Tick, so it had to proceed to the

next part. But it's not doing that.

I'm not sure what's happening there actually. It becomes far more easy when the understanding about the Mechanism is clear.

I'd request to explain things a bit if possible with pieces of codes.

That Helps a lot.

Thanks

Keith Watford
Moderator
9644
Keith Watford 2014.05.06 21:28  
GumRai:


When you want people to help you, you have to pay attention to their advice and implement it.

You are doing nothing in your code to delete an object with the same name or check whether the object exists already.

It is quite obvious that you ran this code to create the first object, then added code to create the 2nd.

Because the first object already exists, you get the error and then return(0)

So the code for the 2nd object will not be implemented.


Open your Objects List, delete "New_Rectangualr_object" and then run your code
Arav007
412
Arav007 2014.05.07 00:31  
GumRai:

Open your Objects List, delete "New_Rectangualr_object" and then run your code


Thanks a lot Man!

It worked!

At first I deleted the Object, then ran the code and got Two rectangles.

But still there was Error showing at every tick. So I placed your object deleting code and now there is NO Error!

Great!

I'll keep experimenting and will get back if encounter any more problem.

Regards

123
To add comments, please log in or register