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

 
ijonhson:

The question is whether I should calculate the indicator code 900 times per one tick (3 timeframes with 300 bars for example), or 3 times. It is clear that icustom is less of a hassle, I put it in the loop and it's done. As an option, I saw an address of the array of indicator values passed to an EA using dll, but I don't want to take the indicator in a set


Again, there is a mistake in the problem statement. Why do you need 900 bars in your Expert Advisor? If you really need so much data in the indicator, 900 bars, then work with them in the indicator itself, why drag them into the Expert Advisor? The right task is 50% of success

 
Nikolay Ivanov:

The problem statement is wrong again... Why do you need 900 bars in your EA? If you really need so much data in the indicator, 900 of them, then work with them in the indicator itself, why drag them into the Expert Advisor? The correct task is 50% of success


I need to compare the minimum and maximum peaks of the indicator at 3 timeframes for example 5min 15min and 30min, to determine the trends, I will not be able to guess the peaks, that is to have to take turns over the entire history. I took 300 bars of history as an example.

It is still too resource consuming to use icustom.

 
ijonhson:

I need to compare the minimum and maximum peaks indicator for 3 timeframes for example 5min 15min and 30min, to determine the trends, I will not be able to guess the peaks, that is to have to look through the entire history. I took 300 bars of history as an example.

It is still too resource intensive to use icustom.


The question remains open in ontick, the IndicatorCounted() function in the first calculation gives -1, how can it be replaced in an Expert Advisor?

 
ijonhson:

"You don't need to change it" - i.e. it works correctly with onTick in Expert Advisor as well as with onCalculate in the indicator?

No, I meant that it is not needed there at all.

 
Alexey Viktorov:

No, I meant there's no need for it there at all.


Dug uphttps://www.mql5.com/ru/articles/1456, I'll look into it, but I thought there was an easier option.

Перенос кода индикатора в код эксперта. Строение индикатора.
Перенос кода индикатора в код эксперта. Строение индикатора.
  • 2007.02.16
  • Nikolay Kositsin
  • www.mql5.com
Прежде чем приступить к основной теме статьи, мне следовало бы вкратце коснуться общего строения индикатора под углом зрения программиста, которого этот индикатор интересует, как будущая часть кода эксперта: Вполне естественно, что у реального индикатора может быть другое количество отображаемых индикаторных значений, другое количество...
 
ijonhson:

The question remains open in the ontick function IndicatorCounted() at the first check how to replace it in the Expert Advisor?

You do not need to look through the tops on every tick, they do not change.

In the EA, check the cycle at the bar opening and exit the cycle as soon as the top is found.

   int count=Bars(Symbol,Period);
   for(int i=0; i<count; i++) {
     // ищем и запоминаем в переменную, если нашли break;
   }
 
ijonhson: The question remains open in ontick, the IndicatorCounted() function in the first calculation gives -1, what will replace it in the Expert Advisor?

The IndicatorCounted() function was previously used in indicators with the start() function. The new indicators with OnCalculate() use the second parameter prev_calculated instead. I analysed them specially and found that they differ by 1. The difference is small and they show how many bars have already been calculated. If it is 0 (or -1), then all bars need to be calculated. This happens when starting the indicator, when it must draw the whole line and save the result in the buffer arrays. On next ticks, only the data of the last bar should be recalculated. Therefore, what is done at zero (or -1) value should be placed in OnInit() of the EA. The rest - very little - should be placed in OnTick()

 
YarTrade:

Thank you. I'll work on it. I didn't read anything about long type in the textbook for some reason.

You need to put cursor on long int or short (or any other language word) and press F1.

 
ijonhson:

Thanks a lot, but as far as I understand from the description of the function, it will execute all the code of the indicator to get one value, in the place I have specified, that is, to get all the tops I will need to calculate the code of the indicator nth time (go through all the bars one by one), but I need to compare the order of the tops of this indicator on several timeframes.

And then you have to look for tops manually

This is absolutely wrong! All the indicator bars, when called from the Expert Advisor using iCustom(), are recalculated only once! All of the following calls of the indicator work with the already calculated results, only the uncalculated bars from the previous call are recalculated. For example, when calling the M15 period indicator from the H1 chart on each new bar, it turns out that 4 15-minute bars are not recalculated from the call to the indicator. So, only these 4 bars will be recalculated.

Even if we loop through the sequence of bars from 0 to xxx, the indicator will be recalculated only once at the first call. All following calls will not perform any recalculation.

 
ijonhson:

Dug uphttps://www.mql5.com/ru/articles/1456, I'll look into it, but I thought there was an easier way

This is a bad example. It's already TEN years old!!! The language has already changed for the better.

Reason: