MQL4参考 物件函数 ObjectMove

ObjectMove

The function changes coordinates of the specified anchor point of the object at the specified chart. There are two variants of the function:

bool  ObjectMove(
   string     object_name,   // object name
   int        point_index,   // anchor point number
   datetime   time,          // Time
   double     price          // Price
   );

The function changes coordinates of the specified anchor point of the object.

bool  ObjectMove(
   string     object_name,   // object name
   int        point_index,   // anchor point number
   datetime   time,          // Time
   double     price          // Price
   );

Parameters

object_name

[in]  Name of the object.

point_index

[in]  Index of the anchor point. The number of anchor points depends on the type of object.

time

[in]  Time coordinate of the selected anchor point.

price

[in]  Price coordinate of the selected anchor point.

Return Value

If successful, returns true, in case of failure returns false. To read more about the error call GetLastError().

Note

The function moves an object coordinate in the chart. Objects can have from one to three coordinates depending on their types. The object coordinates are numbered starting from 0.

Example:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   string obj_name="trend_line";
   long current_chart_id=ChartID();
//---
   datetime t1=Time[0];
   double p1=Close[0];
//---
   datetime t2=Time[1];
   double p2=Close[1];
//--- creating trend line object
   if(!ObjectCreate(obj_name,OBJ_TREND,0,t1,p1,t2,p2))
     {
      Print("Error: can't create trend line! code #",GetLastError());
      return(0);
     }
//--- set color to Red
   ObjectSetInteger(current_chart_id,obj_name,OBJPROP_COLOR,clrRed);
//--- moving of the trend line
   for(int i=1; i<200; i++)
     {     
      t2=Time[i];
      p2=Close[i];
      //--- move the 2nd anchor point of the trend line
      ObjectMove(obj_name,1,t2,p2);
      //--- forced chart redraw
      ChartRedraw(current_chart_id);
      Sleep(100);
     }
//--- sleep to see the object
   Sleep(3000);
//--- delete object
   ObjectDelete(obj_name);
   return(0);
  }