HELP me --> Metatrader Bag (Angle Line)--OBJ_TRENDBYANGLE

 
Hello my frinds .
I Have big problem .


Description for Up picture :

When the line is made, it does not give me its Angle twice.
One in that OnInt ().
One in that OnTick ().
The third time a new price tick appears, it returns the correct value.
What is wrong ?
Why not turn the angle the first time?
Is there a problem with MetaTrader?
Is there a problem with the code?
In any case, thank you for your help.
A world, thank you dear friend.

If there is a real problem with my code, thank you for Tell me what code to use to fix my problem.
int OnInit()
  {
   Print("===========================");
   Print("OnInit");
   Print("===========================");
   Trend_Line_By_Angle(0,"HELLO",0,Time[10],High[10],Time[0],Low[0],0,false,clrRed,STYLE_SOLID,1,false,true,true,false,0);
   Print("Angle = ", ObjectGetDouble(0,"HELLO",OBJPROP_ANGLE));
   for(int i=-2; i<2; i++)
     {
      Print("i = ",i,"   Value = ",ObjectGetValueByShift("HELLO",i));
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
bool x =false ;// Only once
void OnTick()
  {
   Print("===========================");
   Print("OnTick");
   Print("===========================");
   Print("Angle = ", ObjectGetDouble(0,"HELLO",OBJPROP_ANGLE));
   if(!x)
     {
      x = true ;
      for(int i=-2; i<=2; i++)
        {
         Print("i = ",i,"   Value = ",ObjectGetValueByShift("HELLO",i));
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool Trend_Line_By_Angle(const long            chart_ID=0,        
                         const string          name="TrendLine",  
                         const int             sub_window=0,     
                         datetime              time1=0,           
                         double                price1=0,          
                         datetime              time2=0,          
                         double                price2=0,          
                         const double          angle=45.0,        
                         const bool            AG=false,          
                         const color           clr=clrRed,        
                         const ENUM_LINE_STYLE style=STYLE_SOLID, 
                         const int             width=1,           
                         const bool            back=false,        
                         const bool            selection=true,   
                         const bool            ray_right=true,   
                         const bool            hidden=false,     
                         const long            z_order=0)         
  {
   ResetLastError();
   if(ObjectCreate(chart_ID,name,OBJ_TRENDBYANGLE,sub_window,time1,price1,time2,price2))
     {
      //ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
      ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
      ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
      ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
      ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
      ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
      ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
      ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
      ChartRedraw();
      return(true);
     }
   else
     {
      Print(__FUNCTION__,
            ": failed to create => ",name," object! Error code = ",GetLastError());
      return(false);
     }
  }
//+------------------------------------------------------------------+

 
 
Alain Verleyen:

Hello.

Thank you for watching my questions.

I'm very sorry, but instead of being upset, guide me.

 

Abdolmobin Khezri:

One in that OnInt ().
One in that OnTick ().
The third time a new price tick appears, it returns the correct value.
What is wrong ?

You return from OnTick. Then the objects are drawn. Don't read them prior.

 

Objects are drawn asynchronously.

https://www.mql5.com/en/docs/objects/objectcreate

Return Value

The function returns true if the command has been successfully added to the queue of the specified chart, or false otherwise. If an object has already been created, an attempt is made to change its coordinates.


You have to make sure the object exists on the chart before attempting to read its properties.

https://www.mql5.com/en/docs/objects/objectfind

Documentation on MQL5: Object Functions / ObjectCreate
Documentation on MQL5: Object Functions / ObjectCreate
  • www.mql5.com
ObjectCreate - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Abdolmobin Khezri:

Hello.

Thank you for watching my questions.

I'm very sorry, but instead of being upset, guide me.

 
William Roeder:

You return from OnTick. Then the objects are drawn. Don't read them prior.

Hello Dear William Roeder .
Thank You . 
Can you explain more?
Thank You very much .
I have been working on the method for a long time to solve the problem.

 

 
Alexandre Borela:

Objects are drawn asynchronously.

https://www.mql5.com/en/docs/objects/objectcreate

Return Value

The function returns true if the command has been successfully added to the queue of the specified chart, or false otherwise. If an object has already been created, an attempt is made to change its coordinates.


You have to make sure the object exists on the chart before attempting to read its properties.

https://www.mql5.com/en/docs/objects/objectfind

Hello Dear  Alexandre Borela Thank you very much . 


I used the ObjectFind function, but it returns the output of function 0, which means the object is created. But it returns the angle to 0 again.

I had not read the reference. However, with your explanation, new knowledge was added to me. But my problem is still unresolved.

I did not solve my problem using the ObjectFind function because ObjectFind returns a value of 0, which means that the object is built.

But it returns the angle to zero again.

 
Alain Verleyen:


my dear friend .

If you do not have the power to help me and you can not help me, please do not make fun of me and shut your mouth and just watch.

 
Abdolmobin Khezri:


my dear friend .

If you do not have the power to help me and you can not help me, please do not make fun of me and shut your mouth and just watch.

I am not your friend in any way.

Your issue has been discussed numerous time on this forum, so my posts. You are not only unable to use the search engine but also to stay civil, using a lot of fake "dear".

You don't deserve any help.

 
Alain Verleyen:

I am not your friend in any way.

Your issue has been discussed numerous time on this forum, so my posts. You are not only unable to use the search engine but also to stay civil, using a lot of fake "dear".

You don't deserve any help.

If you could help, you would help me instead of making fun of me.

You're not God who determines deserve.
by

Reason: