Download MetaTrader 5

Can draw object with EA (when its run) on chart in mq4 ~ mq5 code expert?

To add comments, please log in or register
Interested in social trading? Read the article!
Mehrdad Shiri
4480
Mehrdad Shiri 2016.01.13 09:42 

hi;

Can draw object with EA (when its run) on chart in  mq4  code expert ?

what about  mq5 ?

Mohammad Soubra
25001
Mohammad Soubra 2016.01.13 10:49  
Yes of course
Mehrdad Shiri
4480
Mehrdad Shiri 2016.01.13 11:50  

hi

thx to reply:

my ea work well for mt4 in mq4 file ,

i add heighlighted line to draw vline.

when i send order i want to have  a vertical line , as below i have it :

.
.
.
int ORDER_BUY=OrderSend(Symbol(), OP_BUY, LOT, ask_price, Slippage,SL,TP,Comment_mark+ "-" + level_count(),Magic_buy,0,HotPink);
      ObjectCreate(0,"Line_buy",OBJ_VLINE,0,Time[open_buy_time],open_buy_price);
      if (ORDER_BUY < 0) { Print(" ERROR in send BUY: ", GetLastError());} //continue;
        else {Print("BUY Ordered successfully");buy_position_modified="no";buy_position_exist="yes";}
,
,
,

there is no error or warning with compiling

, and also no problem when run ea

but no effect to draw  vlline.!what is wrong ?

Alain Verleyen
Moderator
30737
Alain Verleyen 2016.01.13 11:56  

Always check the return value when you are using an mql function.

Return Value

Returns true or false depending on whether the object is created or not. To read more about the error call GetLastError(). If the object has been created already, the function tries to change its coordinates.

Mehrdad Shiri
4480
Mehrdad Shiri 2016.01.13 12:56  
Alain Verleyen:

Always check the return value when you are using an mql function.

THANK you ,

i forget it.

there is : error 4200

  i will check it . please see the result if i asked for help. thank you again , Alain .

Mehrdad Shiri
4480
Mehrdad Shiri 2016.01.14 04:12  

hi,

its draw the line for first time but it must create new line in future by another order and delete that created before.

my code is below.

     int ORDER_BUY=OrderSend(Symbol(), OP_BUY, LOT, ask_price, Slippage,SL,TP,Comment_mark+ "-" + level_count(),Magic_buy,0,HotPink);
      if (ORDER_BUY < 0) { Print(" ERROR in send BUY: ", GetLastError());} //continue;
        else {Print("BUY Ordered successfully");buy_position_modified="no";buy_position_exist="yes";}
      //--- delete all objects
      
   for(int j=ObjectsTotal()-1;j>=0;j--)
         {
          if(StringFind(ObjectName(0,j),"Line_bulls")!=-1)
          if(!ObjectDelete(0,ObjectName(0,j)))
             Print("*****---> Error in deleting object (",GetLastError(),")");
         }        
   
   /*
   int obj_total=ObjectsTotal();
   PrintFormat("Total %d objects",obj_total);
   for(i=obj_total-1;i>=0;i--)
     {
      string name="Line_bulls";//  ObjectName(i);
      PrintFormat("object %d: %s",i,name);
      ObjectDelete(0,name);
     }
   */
      //ObjectCreate(0,"Line_bulls",OBJ_VLINE,0,Time[open_buy_time],open_buy_price);
      if(!ObjectCreate(0,"Line_bulls",OBJ_VLINE,0,Time[open_buy_time],open_buy_price)) { Print(" can not draw VLINE: ", GetLastError());};
      
     }   
   //------------------- III

its delete the old vline but did not create a new vline at new candle sor new order .

where is the problem?

add:  and no error printed.

Roberto Jacobs
46460
Roberto Jacobs 2016.01.14 06:09  
Mehrdad Shiri:

hi,

its draw the line for first time but it must create new line in future by another order and delete that created before.

my code is below.

its delete the old vline but did not create a new vline at new candle sor new order .

where is the problem?

The problem is: the object name remains the same "Vline_bulls", although the "VLine" different Time [] of coordinates.

To resolve your problem, your code should be changed as follows:

if(!ObjectCreate(0,"Line_bulls"+string(TimeToString(Time[open_buy_time],TIME_DATE|TIME_MINUTES)),OBJ_VLINE,0,Time[open_buy_time],open_buy_price)) 
 {Print(" can not draw VLINE: ", GetLastError());}
// With this code, so any object "Vline" has a different name.
Trinh Dat
37203
Trinh Dat 2016.01.14 06:11  
 if(!ObjectCreate(0,"Line_bulls",OBJ_VLINE,0,Time[0],ask_price)) { Print(" can not draw VLINE: ", GetLastError());};
Mehrdad Shiri
4480
Mehrdad Shiri 2016.01.14 06:19  
Roberto Jacobs:
The problem is: the object name remains the same "Vline_bulls", although the "VLine" different Time [] of coordinates.

To resolve your problem, your code should be changed as follows:

i have function to delete even with same name befor create it again. is what you say necessary ?

add:  and no error printed.

Mehrdad Shiri
4480
Mehrdad Shiri 2016.01.14 06:31  
Roberto Jacobs:
The problem is: the object name remains the same "Vline_bulls", although the "VLine" different Time [] of coordinates.

To resolve your problem, your code should be changed as follows:

TRY that, still have problem.
Roberto Jacobs
46460
Roberto Jacobs 2016.01.14 06:44  
Mehrdad Shiri:
TRY that, still have problem.

See the code on my MT4 indicator SBVolumeAvg

and for deleted the VLine use code:

   int obj_total=ObjectsTotal();
   PrintFormat("Total %d objects",obj_total);
   for(i=obj_total-1;i>=0;i--)
     {
      string name="Line_bulls"+string(TimeToString(Times[i],TIME_DATE|TIME_MINUTES)));//  ObjectName(i);
      PrintFormat("object %d: %s",i,name);
      //ObjectDelete(0,name);
      ObjectDelete("Line_bulls"+string(TimeToString(Times[i],TIME_DATE|TIME_MINUTES)));
     }
   //-- Thus, all objects VLine "Line_bulls"+ will be deleted

123
To add comments, please log in or register