Download MetaTrader 5

OjectMove

To add comments, please log in or register
fly7680
698
fly7680  

I created a simple rectangle with 2 buffer and I would like to move the object along with the buffer, with each tick i delede and recreate the object, but I do not think is correct, there is a right way?


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   ArrayInitialize(Buffer1,0); 
   ArrayInitialize(Buffer2,0);
   
   int i=0;
           
           for(int Q=0;Q<2500;Q++){
           ObjectDelete("ZonaUp1");                 
           }   
               
               for(i=0;i<=5;i++){
               
                  Buffer1[i]=High[5];  
                  Buffer2[i]=Low [5]; 
                  // Rettangolo Set and Coordinates
                  ObjectCreate("ZonaUp1",OBJ_RECTANGLE, 0, Time[0], High[5], Time[5], Low[5]);
                  ObjectSet   ("ZonaUp1",OBJPROP_BACK, true);
                  ObjectSet   ("ZonaUp1",OBJPROP_COLOR,Green);  
                 }  
                 
                
   return(rates_total);
  }
whroeder1
16574
whroeder1  
  1.            for(int Q=0;Q<2500;Q++){
               ObjectDelete("ZonaUp1");                 
               }
    Why are you deleting it 2500 times? Once is enough
  2.               for(i=0;i<=5;i++){
                   
                      Buffer1[i]=High[5];  
                      Buffer2[i]=Low [5];
    What use are those two buffers? They contain constants.
  3.                for(i=0;i<=5;i++){
                      ObjectCreate("ZonaUp1",OBJ_RECTANGLE, 0, Time[0], High[5], Time[5], Low[5]);
    Why are you creating it in a loop. You can only create one with the same name?
  4. Create it in OnInit. Move it after your loop. Once per tick.
fly7680
698
fly7680  
Gate 2500 times to be sure to remove all objects created in the chart, I entered the buffer for future use. I entered the rectangle in the loop to make it move along with Buffer.
I did not understand what I should do in OnInit ???
whroeder1
16574
whroeder1  
fly7680: Gate 2500 times to be sure to remove all objects created in the chart,
  1. That's not how you remove all objects.
  2. ObjectDelete("ZonaUp1")
    You are deleting the same object 2500 times.
honest_knave
Moderator
2293
honest_knave  
   string name="ZonaUp1";
   ObjectSetDouble(0,name,OBJPROP_PRICE,0,High[5]);   // set first price
   ObjectSetDouble(0,name,OBJPROP_PRICE,1,Low[5]);    // set second price
   ObjectSetInteger(0,name,OBJPROP_TIME,0,Time[0]);   // set first time
   ObjectSetInteger(0,name,OBJPROP_TIME,1,Time[5]);   // set second time
Marco vd Heijden
Moderator
5957
Marco vd Heijden  

Also you can use

ObjectsDeleteAll()
Function but it's not advisable to delete and create all or many objects over and over on each tick since that seemed to be the issue.
fly7680
698
fly7680  
Marco vd Heijden:

Also you can use

Function but it's not advisable to delete and create all or many objects over and over on each tick since that seemed to be the issue.
That's right, the problem is precisely the object update instead of elminarlo every tick I want to update the way that the rectangle follow the Buffer
whroeder1
16574
whroeder1  
So do it. Your question was already answered. I'll repeat it: "Create it in OnInit. Move it after your loop. Once per tick."
To add comments, please log in or register