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.
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_windowstring name="probe";
bool first_tick=false; // false - ещё не было тиков//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- indicator buffers mapping//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//---staticint 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 callreturn(rates_total);
}
//+------------------------------------------------------------------+//| Deinit |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
ObjectDelete(name);
EventKillTimer();
}
//+------------------------------------------------------------------+
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.
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.
Try using ChartRedraw() after creation, then check size.
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:
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. (chuckles) I'll simulate a few ticks at the weekend.
Is there a function that would return whether the object is rendered?
and WindowRedraw wouldn't help not to wait for a tick?