Download MetaTrader 5

Speed Up Object Creation

To add comments, please log in or register
Richard Read
334
Richard Read  

Hi,

 

I have an indicator, and part of the code draws trend lines on the chart. There are roughly 200 of these lines on each chart, and i have 12 charts running at once. When I change timeframes, obviously all the trend lines need to be redrawn, and with 12 charts open it its very sluggish.

 

Is there a more efficient way to get the indicator to draw these lines when the indicator is initialized, without reducing the number of bars back the indicator looks? Here is the piece of code that draws the lines:

 

void DoBVLines()
  {
   for(int i=loop-1;i>=0;i--)
     {
      if(IgnoreRed==false && i>0 && red[i]>0)
        {
         string name="BV Line "+Time[i];
         //ObjectDelete(0,name);
         if(ObjectFind(0,name)<0)
           {
            double value=LineOffset*Point;//((iATR(Symbol(),0,50,0))*LineOffset)/100;
            ObjectCreate(0,name,OBJ_TREND,0,Time[i],Low[i],Time[i],0);
            ObjectSetInteger(0,name,OBJPROP_COLOR,clrRed);
            ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
            ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
            ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
            //break;
           }
        }

      if(IgnoreLime==false && i>0 && green[i]>0)
        {
         string name="BV Line "+Time[i];
         //ObjectDelete(0,name);
         if(ObjectFind(0,name)<0)
           {
            double value=LineOffset*Point;//((iATR(Symbol(),0,50,0))*LineOffset)/100;
            ObjectCreate(0,name,OBJ_TREND,0,Time[i],Low[i]-value,Time[i],0);
            ObjectSetInteger(0,name,OBJPROP_COLOR,clrLime);
            ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
            ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
            ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
            //break;
           }
        }
      if(IgnoreMagenta==false && i>0 && magenta[i]>0)
        {
         string names="BV Line "+Time[i];
         //ObjectDelete(0,names);
         if(ObjectFind(0,names)<0)
           {
            double value=LineOffset*Point;//((iATR(Symbol(),0,50,0))*LineOffset)/100;
            ObjectCreate(0,names,OBJ_TREND,0,Time[i],Low[i]-value,Time[i],0);
            ObjectSetInteger(0,names,OBJPROP_COLOR,clrMagenta);
            ObjectSetInteger(0,names,OBJPROP_SELECTABLE,false);
            ObjectSetInteger(0,names,OBJPROP_HIDDEN,true);
            ObjectSetInteger(0,names,OBJPROP_STYLE,STYLE_DOT);
            //break;
           }
        }
      if(IgnoreWhite==false && i>0 && white[i]>0)
        {
         string name="BV Line "+Time[i];
         //ObjectDelete(0,name);
         if(ObjectFind(0,name)<0)
           {
            double value=LineOffset*Point;//((iATR(Symbol(),0,50,0))*LineOffset)/100;
            ObjectCreate(0,name,OBJ_TREND,0,Time[i],Low[i]-value,Time[i],0);
            ObjectSetInteger(0,name,OBJPROP_COLOR,clrWhite);
            ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
            ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
            ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
            //break;
           }
        }
     }
  }

 Any thoughts appreciated!

To add comments, please log in or register