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

 
Alexandr Sokolov:

I have a code that is not executed in MQL5 in my indicator

The thing is, ifprice == STO_LOWHIGH everything works correctly, but if price == STO_CLOSECLOSE the function assigns to static variables only

... bypassing the loop

but this exact same function works correctly in MQL4

 
Alexandr Sokolov:

but the same function works correctly in MQL4

Then we need to clarify what arrays High[] Close[]

If they are from mql4, they are not available in mql5, if they are custom... I can't make any suggestions.

 
Alexandr Sokolov:

I want to get the usual maxHigh and minLow stochastics within the period K by Low/High and Close/Close

Low/High during initialization works fine, but Close/Close does not

It's easier to find fmax() or fmin() from the array obtained by CopyBuffer()

 
Alexey Viktorov:

Then we need to clarify what arrays High[] Close[] are

If they are from mql4, they are not available in mql5, if they are custom... I cannot make any assumptions.

Here is the content of these buffers in MQL5

int count = rates_total - prev_calculated, copied = 0; if(count < (int)kperiod + (int)dperiod + (int)slowing) {count = (int)kperiod + (int)dperiod + (int)slowing;};
   if(mode == m1 && price == STO_LOWHIGH) {copied = CopyOpen(_Symbol,PERIOD_CURRENT,0,count,Open); if(copied != count) return(0);};
   if(price == STO_LOWHIGH) {copied = CopyHigh(_Symbol,PERIOD_CURRENT,0,count,High); if(copied != count) return(0);};
   if(price == STO_LOWHIGH) {copied = CopyLow(_Symbol,PERIOD_CURRENT,0,count,Low); if(copied != count) return(0);};
   copied = CopyClose(_Symbol,PERIOD_CURRENT,0,count,Close); if(copied != count) return(0);
 
Alexey Viktorov:

It is easier to find fmax() or fmin() from the array obtained by CopyBuffer()

I need values not from the whole buffer, but within a period K
Otherwise how to implement it, taking into account that I need to copy data taking into account the period of deceleration?

 
Alexandr Sokolov:

I don't need values from the whole buffer, but within the period K
Otherwise, how can I implement this, given that I need to copy the data taking into account the deceleration period?

Yesterday I did the same thing, only with high and low arrays

   for(i = limit; i < rates_total; i++)
    {
     UpperBuf[i] = high[ArrayMaximum(high, i-period, period)];
     LowerBuf[i] = low[ArrayMinimum(low, i-period, period)];
     MidBuf[i] = (UpperBuf[i]+LowerBuf[i])/2;
    }

Without time series flip. So, as laid down in mql5? zero bar on the left.

Plus it's possible to copy indicator buffer not the whole buffer, but only the specified amount from specified bar. And I mistakenly recommended fmax() and fmin(). I meant ArrayMaximum()

 
Alexandr Sokolov:

I want to get the normal maxHigh and minLow stochastics within a period K by Low/High and Close/Close

Low/High during initialization works fine, but Close/Close does not

There are standard functions for time series

Maximum=iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,num,startbar));
Minimum=iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,num,startbar));
 
Taras Slobodyanik:

there are standard functions for timeseries

It is advisable to start reading from the beginning to get good advice. From where the first question was and the rest of the discussion.

 
Alexey Viktorov:

It is advisable to start reading from the beginning for good advice. From where the first question was and the rest of the discussion.

It seems that from the very beginning - the man is going through the time series in search of min/max.
It is possible to do without it.

void KValues(int i)
  {
   if (price == STO_LOWHIGH)
      {
      vhigh=iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,kperiod,i));
      vlow=iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,kperiod,i));
      }
   else
      {
      vhigh=iClose(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_CLOSE,kperiod,i));
      vlow=iClose(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_CLOSE,kperiod,i));
      }
  }
(didn't check).
 
Taras Slobodyanik:

Seems to have looked at it from the beginning - the man is going through the timeseries looking for min/max.
You could do without it.

(didn't check).

He wants stochastic values.

Although... I'm already confused myself what it needs. It looks like stochastic condition, but it copies bars...