Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1149

 
Good afternoon... Probably a simple question, but I can't figure out where to start. I need a script that draws a rectangle with a name containing the date and time of creation. Maybe someone has an example that I can fit to my task.

Thanks in advance :).
 
svob:
Good afternoon... Probably a simple question, but I can't figure out where to start. I need a script that draws a rectangle with a name containing the date and time of creation. Maybe someone has an example that I can fit to my task.

Thanks in advance :).

Take theOBJ_RECTANGLE reference example as a basis,

but change this line

//--- создадим прямоугольник
   if(!RectangleCreate(0,InpName,0,date[d1],price[p1],date[d2],price[p2],InpColor,
      InpStyle,InpWidth,InpFill,InpBack,InpSelection,InpHidden,InpZOrder))
     {
      return;
     }

to this:

//--- создадим прямоугольник
   if(!RectangleCreate(0,TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS),0,date[d1],price[p1],date[d2],price[p2],InpColor,
      InpStyle,InpWidth,InpFill,InpBack,InpSelection,InpHidden,InpZOrder))
     {
      return;
     }
Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Типы объектов / OBJ_RECTANGLE
Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Типы объектов / OBJ_RECTANGLE
  • www.mql5.com
//| Cоздает прямоугольник по заданным координатам                    |               time1=0,                            price1=0,                         time2=0,                            price2=0,                        width=1,            //| Перемещает точку привязки прямоугольника                         |...
 
Vladimir Karputov:

Use theOBJ_RECTANGLE reference example as a basis,

only change this line

to this:

Thank you! :) Got it...

 
Good afternoon, does the number of decimal places in the indicator (in the separate window) depend on the _Digits of the tool? If so, how can I bypass it? The indicator gets fractional values, while it only draws integer ones on the scale.
 
VANDER:
Hi. Does the number of decimal places in an indicator (in a separate window) depend on _Digits of a symbol? If so, how can you avoid it? The indicator produces fractional values, while it displays only integers on the scale.

Example indicator [data folder]\MQL5\Indicators\Examples\ATR.mq5

OnInit() -> set accuracy of displaying

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- check for input value
   if(InpAtrPeriod<=0)
     {
      ExtPeriodATR=14;
      printf("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",InpAtrPeriod,ExtPeriodATR);
     }
   else ExtPeriodATR=InpAtrPeriod;
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
//---
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn


Example #2 -> [data folder]\MQL5\Indicators\Examples\Custom Moving Average.mq5

here the accuracy is higher

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);


Example #3 -> [data folder]\MQL5\Indicators\Examples\ADX.mq5

there is always precision of two values - regardless of Digits()

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- check for input parameters
   if(InpPeriodADX>=100 || InpPeriodADX<=0)
     {
      ExtADXPeriod=14;
      printf("Incorrect value for input variable Period_ADX=%d. Indicator will use value=%d for calculations.",InpPeriodADX,ExtADXPeriod);
     }
   else ExtADXPeriod=InpPeriodADX;
//---- indicator buffers
   SetIndexBuffer(0,ExtADXBuffer);
   SetIndexBuffer(1,ExtPDIBuffer);
   SetIndexBuffer(2,ExtNDIBuffer);
   SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,ExtTmpBuffer,INDICATOR_CALCULATIONS);
//--- indicator digits
   IndicatorSetInteger(INDICATOR_DIGITS,2);
 

Is it possible to access other charts in the strategy tester in visual mode (in multicurrency testing). For example:

int OnInit()
  {
   int bars=iBars("EURUSD",PERIOD_H1);
   bars=iBars("GBPUSD",PERIOD_H1);
   bars=iBars("USDJPY",PERIOD_H1);
   
   return(INIT_SUCCEEDED);
  }
void OnTick()
  {
   long arr[];
   ArrayResize(arr,1);
   arr[0]=ChartFirst();
   long id=arr[0];
   while (!IsStopped()){
      id=ChartNext(id);
      if(id>=0){
         int s=ArraySize(arr);
         ArrayResize(arr,s+1);
         arr[s]=id;
      }
      else break;
   }
   Comment("Total charts: ",ArraySize(arr));   
  }

If you launch this EA in the strategy tester, then the visualizer will open charts of EURUSD, GBPUSD, USDJPY, but

Comment("Total charts: ",ArraySize(arr));

it will show that there is only 1 chart.

 

How do I know the size of the Label in terms of font size and text length? To position it relative to other elements

ObjectGetInteger(0,"label",OBJPROP_XSIZE,0);

Gives 0

Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Свойства объектов
Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Свойства объектов
  • www.mql5.com
Все объекты, используемые в техническом анализе, имеют привязку на графиках по координатам цены и времени – трендовая линия, каналы, инструменты Фибоначчи и т.д.  Но есть ряд вспомогательных объектов, предназначенных для улучшения интерфейса, которые имеют привязку к видимой всегда части графика (основное окно графика или подокна индикаторов...
 
Maksym Mudrakov:

Is it possible to access other charts in the strategy tester in visual mode (in multicurrency testing). For example:

If you launch this EA in the strategy tester, the visualizer will open charts of EURUSD, GBPUSD, USDJPY, but

it will show that there is only 1 chart.

This is a problem with getting the renderer's window handles. And there's no way to beat it.

 
Roman Sharanov:

How do I know the size of the Label in terms of font size and text length? To position it relative to other elements

Gives 0

I use mono-width fonts such as "Courier New", then the width of each character will be approximately the size of the font.
 
indirectly through line length and font size.
Reason: