Download MetaTrader 5

Compiled file size and way of working

To add comments, please log in or register
Thanasis Filippidis
30
Thanasis Filippidis  

I am creating a custom indicator and I am facing a dilemma on the approach I am currently using.

The indicator creates approximately 300-400 labels (prices & calculation results), most of which are live updated, like a hud.

My initial approach was to create each label like that:

obname=Name+" "+"usdc7";
ObjectCreate(obname,OBJ_LABEL,0,0,0);
ObjectSet(obname,OBJPROP_CORNER,0);
ObjectSet(obname, OBJPROP_XDISTANCE, x+3*xs);
ObjectSet(obname, OBJPROP_YDISTANCE, y+yb+6*ys);
ObjectSetText(obname, "T: " + DoubleToStr(usdt,0), FontSize-1, Font, FontC);

However the indicator source file reached critical size (~ 750kb, 20k lines) and was giving me issues in scite with scrolling and finding things.

I then switched to making a custom function to pass my labels:

void LabelMake(const string name,
               const int corner,
               const int x,
               const int y,
               const string label,
               const int FSize,
               const color FCol)
  {
   if(ObjectFind(0,name)<0)
      if(!ObjectCreate(0,name,OBJ_LABEL,0,0,0))
         {
         Print("error: can't create label_object! code #",GetLastError());   
         }
        
         ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
         ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
         ObjectSetText(name,label,FSize,Font,FCol);
         ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
         ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
        
   WindowRedraw();
  }

like that:

obname=Name+" "+"usdc7";
LabelMake(obname,0,x+3*xs,y+yb+6*ys,"T: " + DoubleToStr(usdt,0),FontSize-1,FontC);

Now the resulting source file is ~450kb and 7k lines smaller.

However the odd thing I noticed is that while the compiled file in the first version was approximately 750kb, the new compiled file when using the custom function is ~1.9mb. Tried both by having the custom function in the source itself or as an mqh.

I am wondering whether there are any implications in using the second method, such as slower response times, higher ram usage (didn't see any notable difference) or in cpu usage (cpu seems to have decreased from 8-9% to 3% but this might be due to the time of the day and low volatility).

Can anyone confirm that there shouldn't be really any difference despite the file size in speed/ram/cpu?

Thanks.

To add comments, please log in or register