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

 
Вадим Мотеюнас:
https://www.mql5.com/ru/docs/basis/operators
 
ArturR:

1. Yes, there is a case for zero bar in the code, no possibility to check which case was tested now, I will check tonight.

2. I checked it by outputting a comment to the chart with values, macd, High and Low have values, but min(max)price does not get corresponding values.

I would need to see how these variables are declared. There is a suspicion that they are local variables which are reset to zero with every entry into the function. As a result, those moments when they are with values you simply don't have time to see. To see the values, look at the contents of the log. After all, there is Print in the code.

 

Hello. I have a task, out of 1000 lines of csv file, I need to select parameter matches from field N and return any type of value from other fields of the found record. Can you tell me if there is an expert that works through the file and makes trade decisions? Thank you.

 
mwwm:

Hello. I have a task, out of 1000 lines of csv file, I need to select parameter matches from field N and return any type of value from other fields of the found record. Can you tell me if there is an expert that works through the file and makes trade decisions? Thanks.

Probably need to look for ones that work with news in the code base.

 
Ihor Herasko:

You simply do not have time to see. To see the values, look at the contents of the logbook. After all, there is Print in the code.

Yes it is, thank you ) I did not notice this record among other rubbish in the journal. Thanks again to all who responded, I will continue to clean up)

 
How to calculate the index bar to make the value corresponds to the following logic: if the current period of the chart M15, and timeframe of the called indicator with function (MTF) = H1, the index bar 5, ie the fact of closing the bar H1, if the current period of the graph M30, and timeframe of the called indicator with function (MTF) = H1, the index bar 3, if the current period of the chart M5, and timeframe called indicator with function (MTF) = M15, the index bar 4.
 
lil_lil:
What calculation of the bar index must be done, so that the value corresponds to the following logic: if the current period of the chart M15 and the called indicator timeframe with function (MTF) = H1, the index of bar 5, ie the fact of closing the bar H1, if the current period of the chart M30 and the called indicator timeframe with function (MTF) = H1, then the index of bar 3, if the current period of the chart M5 and the called indicator timeframe with function (MTF) = M15, the index of bar 4.

The error here is in the logic itself. The current TF could be M15, and the last M15 bar, which corresponds to the H1 bar that has formed, would be 1. Or it could be 2, or 3, or 4, but no more. For example, the time is now 10:06. The indices of the current M15 and H1 bars are 0, previous bars in both TFs are 1 and the last M15 bar that corresponds to the closed H1 is also 1. At 10:15 the situation will change: the last M15 bar that formed H1 will have an index 2, at 10:30 it will be 3 and at 10:45 it will be 4.

Mathematical calculations will not help much here. We need to look for the corresponding bars on the chart. The algorithm is as follows:

  1. Determine the time of opening of zero bar H1. (iTime)
  2. Identify the index of the first bar of the current timeframe, which corresponds to the opening time of the H1 zero bar. (iBarShift)
  3. Add 1 to the bar index found.

 
Ihor Herasko:

The error here is in the logic itself. The current TF could be M15, and the last M15 bar, which corresponds to the H1 bar that has formed, would be 1. Or it could be 2, or 3, or 4, but no more. For example, the time is now 10:06. The indices of the current M15 and H1 bars are 0, previous bars in both TFs are 1 and the last M15 bar that corresponds to the closed H1 is also 1. At 10:15 the situation will change: the last M15 bar that formed H1 will have index 2, at 10:30 it will be 3 and at 10:45 it will be 4.

Mathematical calculations will not help much here. We need to look for the corresponding bars on the chart. The algorithm is as follows:

  1. Determine the time of opening of zero bar H1. (iTime)
  2. Identify the index of the first bar of the current timeframe, which corresponds to the opening time of the H1 zero bar. (iBarShift)
  3. Add 1 to the bar index found.

Probably I haven't told it all. The indicator draws on the zero bar of the upper timeframe, conditionally H1, respectively for all 4 bars of the current timeframe, M15. That is why I need index 5 on M15 to know if there is a signal at H1 closing. Surely it is possible to calculate this index to avoid writing a bunch of conditions for each variant of combinations of high and current periods.

input ENUM_TIMEFRAMES   TimeFrame=PERIOD_H1;
//  
 if(TimeFrame == PERIOD_H1&&Period()==M15) timef = 5;//timef = 4;

   if(TimeFrame == PERIOD_H1&&Period()==M30) timef = 3;//timef = 2;


Ajk=NormalizeDouble(iCustom(NULL,0,"Ajk",TimeFrame,4,i+timef),Digits);
 
lil_lil:

The indicator draws on the zero bar of the higher timeframe, usually H1, respectively during all 4 bars of the current timeframe, M15.

That is what I am saying, the bars of the current timeframe may be smaller - 1, 2 or 3. That is, readings will not always be displayed on 4 bars. The only case of 4-bar displaying is the last bar of the current TF which corresponds to zero bar H1. For this formulation of the problem we only need to find the first bar of the current TF that corresponds to zero bar H1:

int nCurTFBarIndex = iBarShift(NULL, 0, iTime(NULL, PEPRIOD_H1, 0));

Then the data will be displayed starting from zero bar of the current TF up to and including nCurTFBarIndex.

That's why I need index 5 specifically on the M15 TF, to find out at the H1 close whether there is a signal left or not. Surely it is possible to calculate this index to avoid writing a bunch of conditions for each variant of combination of higher and current periods.

From which TF is the signal taken: from the current one, from H1 or a mixed version? If only from H1, then there is no need to look for anything at all, because the last formed bar will always have index 1.

 
Ihor Herasko:

From which TF is the signal taken: current, H1 or a mixed version? If only from H1, then there is no need to look for anything at all, because the last formed bar will always have index 1.

I place H1 in external settings of MTF indicator and attach it to M15 chart. The signal flashes for 4 bars. When H1 bar is closed, the signal does not blink and on M15 the signal stops blinking on bar 4. If I put it on М1, respectively, it stops blinking on bar 60. it is necessary to calculate the index i+N so that N varies depending on the selected period in the settings and on the chart of the period, in which the indicator is attached.

input ENUM_TIMEFRAMES   TimeFrame=PERIOD_H1;
//  
 if(TimeFrame == PERIOD_H1&&Period()==M15) N = 5;// ВОЗМОЖНО НУЖНО N = 4;

   if(TimeFrame == PERIOD_H1&&Period()==M1) N = 61;//А ЗДЕСЬ ВОЗМОЖНО N = 60;
Reason: