MQL4 Learning - page 134

 

himladen

Could you please help to Make it work for MT4 Build 600+

Thanks in advance!

Files:
forexhacked.mq4  19 kb
sap_robot.mq4  32 kb
 

Hi Mladen & others,

Can some one help me ? I want to create rectangle, but TIME2 will be changed. Please see attachments. If EMA5 cross EMA20 after the candle close, i want to create a line (rectangle with small height) from the OPEN price of previous candle. And this line/rectangle will always add its length, until the price retrace back and touch it.

Note:

*) If possible, i want to add text to each object, which will show the price of that level

*) we can have some lines (if it is not yet touched by price), so the objName will be unique for each object, i think.

I tried ObjectDelete() , and also ObjectMove() with WindowRedraw(), but it still did not work ...

How to make it ? Any idea will be very helpful, i appreciate it.

Thanks

-pedma

 
pedma:
Hi Mladen & others,

Can some one help me ? I want to create rectangle, but TIME2 will be changed. Please see attachments. If EMA5 cross EMA20 after the candle close, i want to create a line (rectangle with small height) from the OPEN price of previous candle. And this line/rectangle will always add its length, until the price retrace back and touch it.

Note:

*) If possible, i want to add text to each object, which will show the price of that level

*) we can have some lines (if it is not yet touched by price), so the objName will be unique for each object, i think.

I tried ObjectDelete() , and also ObjectMove() with WindowRedraw(), but it still did not work ...

How to make it ? Any idea will be very helpful, i appreciate it.

Thanks

-pedma

pedma

Once when you have an object created, simply use ObjectSet(objectName,OBJPROP_PRICE2,desiredPrice) and that is all. You do not need to do anything else

 
mladen:
pedma Once when you have an object created, simply use ObjectSet(objectName,OBJPROP_PRICE2,desiredPrice) and that is all. You do not need to do anything else

Thanks Mladen. But what i want is to change the TIME2 , not Price2. The rectangle price1 & price2 is always same. The rectangle will grow, if the price does not touch that level, so time2 is the last candle time, if i am not wrong.

Can i use : OBJPROP_TIME2 to replace OBJPROP_PRICE2 ??

And must i use variable x : Time[x] instead of Time[0] ? which it is inside the "for" routine:

for (x=limit; x>=0; x--) {

rectangleTime2 = Time[x];

ObjectSet(name,OBJPROP_TIME2,rectangleTime2);

......

}

Thanks

 
pedma:
Thanks Mladen. But what i want is to change the TIME2 , not Price2. The rectangle price1 & price2 is always same. The rectangle will grow, if the price does not touch that level, so time2 is the last candle time, if i am not wrong.

Can i use : OBJPROP_TIME2 to replace OBJPROP_PRICE2 ??

Or must i use variable x : Time[x] instead of Time[0] ? which it is inside the "for" routine:

Thanks

Sorry, my bad

But it is all in all the same thing : you can use OBJPROP_TIME2

ObjectSet(objectName,OBJPROP_TIME2,desiredTime);

and it will be extended to the time you specify (no need for a move or anything similar). Just make sure that you do it on every tick (don't worry, it is not time consuming). If you wish to align it to current bar, then the "desiredTime" should be Time[0].

 
mladen:
Sorry, my bad

But it is all in all the same thing : you can use OBJPROP_TIME2

ObjectSet(objectName,OBJPROP_TIME2,desiredTime);

and it will be extended to the time you specify (no need for a move or anything similar). Just make sure that you do it on every tick (don't worry, it is not time consuming). If you wish to align it to current bar, then the "desiredTime" should be Time[0].

Thank you very much Mladen,

you are really a great coder !!

Another question:

It will calculate the EMA cross at Multi TimeFrame, so for making each object unique, i try to name the object as :

string myObjName = StringConcatinate("myindicator_",IntegerToString(Period(),0),"_",TimeToStr(TimeCurrent(),TIME_DATE),"_",TimeToStr(TimeCurrent(),TIME_MINUTES));

So, myObjName is like this (example) :

myindicator_H4_2014.06.15_08:10

myindicator_M5_2014.06.18_05:02

myindicator_M5_2014.06.18_37:11

myindicator_M1_2014.09.18_06:15

myindicator_M1_2014.09.18_08:21

myindicator_M1_2014.09.18_08:55

myindicator_M1_2014.09.18_09:48

.... etc ...

edit: i can also add the Price as the ending of the object name ... or use ObjectSetText(.....) above the level.

At the same candle of TF M15 or M30, for example it "could" have 1 object of H4, 1 object of M15, 2 objects of M5 and some objects of M1. I am having problem to get the object, because it "could" be some "unfinished" objects & so many "finished" objects on the chart ....

My idea is to put all of this "unfinished" objects in database, define the Flag of the "unfinished" object to "0" as example, and later i delete this object if it is "finished" (the price has touched this level). So, i can know the objectName of all "unfinished" objects.

After fetching the objectName from database, i can try to get it's TIME2 properties :

T2 = ObjectGet(myObjName, OBJPROP_TIME2);

Error=GetLastError();

if (no error ... ) {

if (currentPrice > OBJPROP_PRICE2) { // object is still "unfinished"

if (T2 != Time[0]) {

ObjectSet(myObjName,OBJPROP_TIME2,T2);

.....

}

}

else { // object is "finished", price touch its level

change color of object ....

delete the entry from database ....

}

}

If i do not use database (if i am not wrong, there is mysql & sqlite3 wrapper for MT4), is there another solution (may be using array/buffer or ...) ?

If using array for example, will the process faster and easier ? Sorry, i have so many questions,

i do not know much about array, and using it to implement this ...

Many Thanks in advance

-pedma

 
pedma:
Thank you very much Mladen,

you are really a great coder !!

Another question:

It will calculate the EMA cross at Multi TimeFrame, so for making each object unique, i try to name the object as :

So, myObjName is like this (example) :

edit: i can also add the Price as the ending of the object name ... or use ObjectSetText(.....) above the level.

At the same candle of TF M15 or M30, for example it "could" have 1 object of H4, 1 object of M15, 2 objects of M5 and some objects of M1. I am having problem to get the object, because it "could" be some "unfinished" objects & so many "finished" objects on the chart ....

My idea is to put all of this "unfinished" objects in database, define the Flag of the "unfinished" object to "0" as example, and later i delete this object if it is "finished" (the price has touched this level). So, i can know the objectName of all "unfinished" objects.

After fetching the objectName from database, i can try to get it's TIME2 properties :

If i do not use database (if i am not wrong, there is mysql & sqlite3 wrapper for MT4), is there another solution (may be using array/buffer or ...) ?

If using array for example, will the process faster and easier ? Sorry, i have so many questions,

i do not know much about array, and using it to implement this ...

Many Thanks in advance

-pedma

pedma

Why don't you simply use the time of the bar at which the object is drawn instead of TimeCurrent()? That way you would have a unique ID that you can always identify and work with (with TimeCurrent() you can not do that since you do not know the exact TimeCurrent() when the object was assigned a name)

 
mladen:
pedma Why don't you simply use the time of the bar at which the object is drawn instead of TimeCurrent()? That way you would have a unique ID that you can always identify and work with (with TimeCurrent() you can not do that since you do not know the exact TimeCurrent() when the object was assigned a name)

Hi Mladen,

Yes, you are right. It is my bad ... it should be Time instead of TimeCurrent().

Thanks a lot for your help. I will try to implement it using database first ...

Best Regards,

-pedma

 

That sounds great, I will give it a try!

 

Hi,

is it possible to create an object werde the objectname isn't pop up, if I put my mouse on the chart on it?

I tried the OBJPROP_HIDDEN, but that's only that my oobject name isn't in the object list, but on the chart I can see the object name...

Reason: