Errors, bugs, questions - page 1456

 
Vasyl Nosal:

Do you have a solution to this issue in an indicator, without ticks?

And I've said it before. It's strange that you can get the text itself without rendering but not the size.

What do ticks have to do with it? The chart is drawn without ticks.

The size of the text label is found out from the display context using the win api function GetTextExtent. The display context gives this information taking into account the screen resolution and selected font size.

When you first create an object, there is no display context. You could, in principle, create it, but you could easily get into a situation where the "artificially" calculated size will be different from the one that was actually calculated during actual rendering. So, until the object is rendered, its size is unknown.

 
Vasyl Nosal:
Try using ChartRedraw() after creation, then check the size.
 
Alexey Kozitsyn:
Try using ChartRedraw() after creation, then check size.
Doesn't work.
 
Vasyl Nosal:
Doesn't work.

In general, you should not draw anything in the indicators before the first event in OnCalculate() - this approach will guarantee the creation of a chart and the correct work with objects.

Approximately like this - at the first tick we create, but the next one SIZE:

//+------------------------------------------------------------------+
//|                                               TestIndicator1.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
string name="probe";
bool first_tick=false; // false - ещё не было тиков
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   static int count;
   if(count>3)
      return(rates_total); // после трёх Алертов выходим. Не за чем слух портить.
   if(!first_tick)
     {
      ObjectCreate(0,name,OBJ_LABEL,0,0,0);
      ObjectSetString(0,name,OBJPROP_TEXT,name);
      first_tick=true;
     }
   else
     {
      string text=ObjectGetString(0,name,OBJPROP_TEXT);
      int text_sizeX=int(ObjectGetInteger(0,name,OBJPROP_XSIZE));
      Alert(text," ",text_sizeX);
     }
   count++;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Deinit                                                           |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectDelete(name);
   EventKillTimer();
  }
//+------------------------------------------------------------------+
 
Karputov Vladimir:

In general, you should not draw anything in the indicators before the first event in OnCalculate() - this approach will guarantee the creation of a chart and the correct work with objects.

Approximately so - on the first tick we create, and on the next one we SIZE:

Okay. I will simulate a couple of ticks at the weekend.
 
Is there a function that would return whether the object is drawn?
 
Vasyl Nosal:
Okay. (chuckles) I'll simulate a few ticks at the weekend.
Switch off the Wi-Fi and you'll have a Saturday :).
 
Vasyl Nosal:
Is there a function that would return whether the object is rendered?
Ask for the size of the text marker
 
would WindowRedraw not help not to wait for a tick?
 
Alexandr Bryzgalov:
and WindowRedraw wouldn't help not to wait for a tick?
No.