Questions from Beginners MQL4 MT4 MetaTrader 4 - page 217

 
alex_xss:

Mmm, maybe.

You're the first one who hasn't had it yet))

But it does not matter, can pop up in anyone - so you have to fix it, unfortunately.

I have a lot of them, it depends on the version of MT4 (I have one from Alpari).

I have a lot of them from different versions, I'm programming for them :-) but the software is still the same, they only differ in small branding and small chips in indicators/advisors.

PS/ colour tricks can be caused by wrong DPI setting of the monitor, presence of "colour temperature correcting utilities", "video card game extensions". And so on and so forth.

PPS/by the way no DC has overcome (more likely due to greed, money) own indicators/advisors/scripts/tools package. At most a cheesy dashboard in corporate colours. Which sort of hints at

 

Hello!
Can you tell me why OBJPROP_XSIZE gives 0?

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnInit()
  {
   ObjectsDeleteAll();
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string mnth=(string)TimeMonth(TimeCurrent())+".";
   string dy=(string)TimeDay(TimeCurrent())+" ";
   string hr=(string)TimeHour(TimeCurrent())+":00 ";

   string TimeSig1=TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES);
   string Label1=" TEST "+Symbol()+"   "+TimeSig1+" Test:  "+mnth+dy+hr+" 1 2 3 4 5 6 7 8 9 10 11";
//string Label1="123456789"+"1"+"123456789"+"2"+"123456789"+"3"+"123456789"+"4"+"123456789"+" 5 "+"123456789";
   obj_create("Sym",Label1,50,clrWhite,15);

  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void obj_create(string name,string object,int Y_distance,color Color,int size)
  {
   if(ObjectFind(name)==-1)
     {
      ObjectCreate(0,name,OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size);
      ObjectSetString(0,name,OBJPROP_FONT,"Rockwell");
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
      ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_LEFT);
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,10);
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,Y_distance);
      ObjectSetInteger(0,name,OBJPROP_COLOR,Color);
     }
   ObjectSetString(0,name,OBJPROP_TEXT,object);

//text size
   int text_sizeX=int(ObjectGetInteger(0,name,OBJPROP_XSIZE));
   
Print(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ obj_create  text_sizeX: ",text_sizeX);   
  }
//+------------------------------------------------------------------+
 
Nauris Zukas:

Hello!
Can you tell me why OBJPROP_XSIZE gives 0?

OBJ_LABEL is a very specific object - after placement and before the first chart update, the width (X_SIZE) is not defined.

It depends on font, dpi of the screen. Until rendering fully works, we can't say anything about real width.

 
Maxim Kuznetsov:

OBJ_LABEL is a very specific object - after placement and before the first chart update, the width (X_SIZE) is undefined.

It depends on the font, dpi of the screen in general. Until rendering fully works, we can't say anything about real width.

Try to redraw it and then check

   ObjectSetString(0,name,OBJPROP_TEXT,object);
   ChartRedraw();
//text size
   int text_sizeX=int(ObjectGetInteger(0,name,OBJPROP_XSIZE));
 
Vitaly Muzichenko:

Try redrawing and then check afterwards

Thank you, I will give it a try!

It didn't work.
 
Maxim Kuznetsov:

OBJ_LABEL is a very specific object - after placement and before the first chart update, the width (X_SIZE) is undefined.

It depends on the font, dpi of the screen in general. Until rendering functions work completely, I can't say anything about real width.


Thanks, the idea is clear, I'll experiment with something.

 
Nauris Zukas:


Thanks, I get the idea, I'll experiment with it.

ChartRedraw does not redraw directly, it just puts a tick somewhere in the depths of the terminal "the chart should be redrawn as soon as possible".

To find out which width the text mark (should) get, you can try TextSetFont, TextGetSize - significant difference can only appear at HiDPI. Or maybe not :-) I haven't tried it

or get the width of real OBJ_LABEL already at the next tick/chart_event, i.e. exactly after repaint

 
Maxim Kuznetsov:

ChartRedraw does not redraw directly, it just puts a tick somewhere in the depths of the terminal "the chart should be redrawn as soon as possible".

To find out which width a text mark (should) get, you can try TextSetFont, TextGetSize - significant difference can only appear at HiDPI. Or maybe not :-) I haven't tried it

or get the width of real OBJ_LABEL already at the next tick/chart_event, i.e. exactly after redrawing

Already got it working, thanks! Added OnDeinit(), put a delay there, and then OBJPROP_XSIZE.
P.S. I couldn't think of anything better to do with the delay in the script:

for(int i=100000000; i>0; i--) {} 
 
Nauris Zukas:

Thanks, it all worked out! I added OnDeinit(), put a delay there, and then OBJPROP_XSIZE.
P.S. I couldn't think of anything better to do with the delay in the script:

// задержка 500 милисекунд, годная для тестера

ulong timestamp=GetTickCount64();

do {

   Sleep(500/4);  // в тестере не сработает, зато спасёт GetTickCount

} while(GetTickCount64()-timestamp<500);

 
Maxim Kuznetsov:

// задержка 500 милисекунд, годная для тестера

ulong timestamp=GetTickCount64();

do {

   Sleep(500/4);  // в тестере не сработает, зато спасёт GetTickCount

} while(GetTickCount64()-timestamp<500);

Thank you, it worked!

   do{}
   while(GetTickCount()-Time11<1000);