Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1249

 
Roman:

Can you tell me if there is a hook for the mql5 indicator? To set two display properties.

And somehow bind different output, each to its own mapping property.

Yes, there is. But it is only for mql5 and it would not work with the Market. In indicators you have to search for an indicator with the name of the second one and if it is not present, then ChartIndicatorAdd().

 
Alexey Viktorov:

There is. But only for mql5 and it won't work for Market. In indicators you have to search for an indicator with the name of the second indicator and if it is not present, then ChartIndicatorAdd().

You have two indicators. Not one with simultaneous double rendering property on the main chart and in the subwindow.

But it will do as a variant of simultaneous launching of two indicators. But the data will need to be obtained from two indicators, not from one.

 
Artyom Trishkin:

Well that's two indicators. Not one with simultaneous dual property of drawing on the main chart and in the sub-window.

Although, as a variant of simultaneous launching of two different indicators, it will do. But the data will need to be obtained from two indicators, not from one.

Yes, that's right, the meaning was to draw on the main chart and in the subwindow, from one code.

Artyom Trishkin:

Use your own drawings on the main chart from the subwindow.

That's where the snag comes in. How do you draw from the subwindow to the graph?
If you have an example, it will be clearer.

 

Please help me with a problem I have encountered. I didn't understand why the calculation I tried didn't help calculate the margin. I am using the formula from:

h ttps://www.mql5.com/ru/docs/constants/environment_state/marketinfoconstants?#enum_symbol_calc_mode

But the problems remained.

Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Для получения текущей рыночной информации служат функции SymbolInfoInteger(), SymbolInfoDouble() и SymbolInfoString(). В качестве второго параметра этих функций допустимо передавать один из идентификаторов из перечислений ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE и ENUM_SYMBOL_INFO_STRING соответственно. Некоторые символы (как правило...
 

Tell me how to translate this code from MQL4 to MQL5:

datetime  bar_day   = TimeDay(Time[Bars - 1]);

?

I tried a lot of variants, here is one of them:

int bars=Bars;
//+------------------------------

   datetime  bar_day   = TimeDayMQL4(iTimeMQL4(NULL,0,(bars - 1)));

I tried a lot of variants, here's the code of TimeDayMQL4 and iTimeMQL4 functions created in MQL4 compatibility library:

int TimeDayMQL4(datetime date)
  {
   MqlDateTime tm;
   TimeToStruct(date,tm);
   return(tm.day);
  }

datetime iTimeMQL4(string symbol,int tf,int index)
{
   if(index < 0) return(-1);
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   datetime Arr[];
   if(CopyTime(symbol, timeframe, index, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}

But it still doesn't work, I get 1970...

 
Sayberix :

Tell me how to translate this code from MQL4 to MQL5:

?

It's easy. Follow this article: https://www.mql5.com/ru/articles/81

Переход с MQL4 на MQL5
Переход с MQL4 на MQL5
  • www.mql5.com
Данная статья, построенная в форме справочника по функциям MQL4, призвана помочь переходу с MQL4 на MQL5. Для каждой функции языка MQL4 приведено описание и представлен способ ее реализации на MQL5, что позволит вам значительно ускорить перевод своих программ с MQL4 на MQL5. Для удобства функции разбиты на группы, как в документации по MQL4.
 
jaffer wilson:

It's easy. Follow the article: https://www.mql5.com/ru/articles/81

Updated my post. Tried it, it doesn't work. I get this value in the variables: D'1970.01.01 00:00:24'

I also use TimeMonthMQL4 and TimeYearMQL4
 
jaffer wilson:

Please help me with a problem I have encountered. I didn't understand why the calculation I tried didn't help calculate the margin. I am using the formula from:

h ttps://www.mql5.com/ru/docs/constants/environment_state/marketinfoconstants?#enum_symbol_calc_mode

But the problem remained.

I haven't figured it out - no clue unfortunately.

 
Roman:

Yes, that's right, the point was to draw on the chart and in the subwindow, from the same code.

Here's the hitch. How to draw from the subwindow to the chart?
If you have an example, it will be easier to understand.

There are two ways to display it on the chart:

  1. Graphic objects
  2. Canvas .

In any case, we will have to make an additional buffer that will not be displayed in the data window, but from which these data can be obtained. The values that can be used for obtaining data from the main window will be written to the buffer. Then it will be possible to receive data both from the sub-window and the main chart from one indicator.

Or, it is more convenient to first write all calculated data for each bar into this buffer and then use this data to build the main chart in the main window. How it is plotted is up to you. I would choose Kanvas.

 
Sayberix:

Updated my post. Tried it, it doesn't work. I get this value in the variables: D'1970.01.01 00:00:24'.

I also use TimeMonthMQL4 and TimeYearMQL4

From the article that Jaffer cited

void OnStart()
{
   datetime Time[];
   int count = 2;        //сколько копируем 
   ArraySetAsSeries(Time, true);
   CopyTime(_Symbol, PERIOD_D1, 0, count, Time); 
   
   Print(Time[1]); //1-окрытие вчерашнего дня, 0-открытие текущего дня
}
Reason: