Actually when using loop, you are making the name becomes unique.
i is the key factor to make the name unique.
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:
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
bool first_rec= ObjectCreate(name,OBJ_RECTANGLE,0, Time, 1.68405, Time, 1.68505, 0, 0);
Print("Error: failed to create First rectangle! Error code:",GetLastError());
bool second_rec= ObjectCreate(name_2,OBJ_RECTANGLE,0, Time,1.68205, Time,1.68305, 0, 0);
Print("Error: failed to create Second rectangle! Error code:",GetLastError());
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.
But I have to provide different prices too.
Also how can I add string with integer in 'name+i'?
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 a lot Man!
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!
I'll keep experimenting and will get back if encounter any more problem.