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

 
Mehrdad Shiri:

its corrected on commented;

but what about for draw line by this line:

this have problem to draw vline

but if i used and change as below , so there is no problem and work good :

?

Example #1:

   if(!ObjectCreate(0,"Line_bulls",OBJ_VLINE,0,open_buy_time,0))
     {
      Print(" can not draw VLINE: ",GetLastError());
     };
 
Karputov Vladimir:

Example #1:

no, it does not effective.

i will simple it (will delete some huge part of code ) my ea and put source here , so you good people can run and help.

all problem to draw vline refer to the below highlighted :

if(!ObjectCreate(0,"Line_bulls",OBJ_VLINE,0,open_buy_time,0))
     {
      Print(" can not draw VLINE: ",GetLastError());
     };

thank you all.

 
Mehrdad Shiri:

no, it does not effective.

i will simple it (will delete some huge part of code ) my ea and put source here , so you good people can run and help.

thank you all.

Before you create a line, check the value of a variable: "open_buy_time". Probably this variable is zero.
 
Karputov Vladimir:
Before you create a line, check the value of a variable: "open_buy_time". Probably this variable is zero.

as you see:

.
.
.
//----------------------
string buy_position_exist= "no";
string buy_position_modified= "yes";
.
.
double open_buy_price;
int Magic_buy = 1;
//------
.
//------
datetime open_buy_time;
datetime zero;
int BAR_open_buy;
double BAR_open_buy_heigh;
double BAR_open_buy_low;
.
.
.
.
//------
    for (int ii0 = OrdersTotal() - 1; ii0 >= 0; ii0--)
       {
        if(OrderSelect(ii0, SELECT_BY_POS, MODE_TRADES)==true)
          {
           if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic_buy) continue;
           if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic_buy)
              { 
               if (OrderType() == OP_BUY) open_buy_price=OrderOpenPrice();
               if(OrderSelect(ii0, SELECT_BY_POS)==true) open_buy_time=(OrderOpenTime());
              }
          }
       }
   BAR_open_buy=Bars(Symbol(),0, open_buy_time, TimeCurrent());
   BAR_open_buy_heigh=High[BAR_open_buy];
   BAR_open_buy_low=Low[BAR_open_buy];
.
//------
.
.
.
 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,open_buy_time,open_buy_price)) { Print(" can not draw VLINE: ", GetLastError());};
      
     }   
   //------------------- III

after i get the order then i will draw line, isnt it ?

 
Mehrdad Shiri:

as you see:

after i get the order then i will draw line, isnt it ?

No. It is not true. It is possible when there are no orders. Then the variable will be equal to zero.

And before you create lines print values of variables: open_buy_time and open_buy_price.

 

P.S.  For a vertical line the variable "open_buy_price" does not need.

 
Karputov Vladimir:
No. It is not true. It is possible when there are no orders. Then the variable will be equal to zero.
And before you create lines print values of variables: open_buy_time and open_buy_price.

as you can see:


with run in first gretting order the var. get his value=/ 0 and no line ?

is it ?

 
Mehrdad Shiri:

as you can see:


with run in first gretting order the var. get his value=/ 0 and no line ?

is it ?

Before you create lines print (in tab "Experts") values of variables: open_buy_time and for a vertical line the variable "open_buy_price" does not need.

   Print("open_buy_time=",TimeToString(open_buy_time));
   ResetLastError();
   if(!ObjectCreate(0,"Line_bulls",OBJ_VLINE,0,open_buy_time,0))
     {
      Print(" can not draw VLINE: ",GetLastError());
     };
 
Karputov Vladimir:
Before you create lines print (in tab "Experts") values of variables: open_buy_time and for a vertical line the variable "open_buy_price" does not need.

;-)

you are right . solved with you thank you.

with search again before to draw line. as below:

.
.
.
      
for (int ix = OrdersTotal() - 1; ix >= 0; ix--) 
       {
         if(OrderSelect(ix, SELECT_BY_POS, MODE_TRADES)==true)                             
           {
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic_buy) continue;
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic_buy) 
               {
                if (OrderType() == OP_BUY) {buy_position_exist="yes";open_buy_time=OrderOpenTime();}
                else buy_position_exist="no";
               }            
           }
       }
      if(!ObjectCreate(0,"Line_bulls",OBJ_VLINE,0,open_buy_time,0)) { Print(" can not draw VLINE: ", GetLastError());};
      
     }   
   //------------------- III

its ok.

and thank to all help.

 
Mehrdad Shiri:

;-)

you are right . solved with you thank you.

with search again before to draw line. as below:

its ok.

and thank to all help.

Glad to help.
Reason: