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

 

Thank you, but she's

Vitaly Muzichenko:

iCustom to help


iCustom is a good solution for iCustom but iCustom always executes the whole code of the indicator, and if i need many indicator parameters in an EA (and it is) then instead of one indicator calculation we will get several, which can significantly slow down the process until the current tick is missed, i forgot about the predefined variables.....

int rates_total=Bars;

defined global variable

int prev_calculated=0;

crashes on number of array elements

 
ijonhson:

I'm sorry, but I don't understand why oncalculate should pass values of predefined variables if they are global and also available

Take a look at an example

//+-------------------------------------------------------+
//|Параметры функции                             PROBA.mq4|
//+-------------------------------------------------------+
#property   strict

void OnStart()
{
 Alert(Сумма(2,5));
 
 int Сум=0;
 Сумма(2,5,Сум);  // Передаем в функцию 2 числа и получаем сумму
 Alert(Сум);
}

int Сумма(int a, int b)
{
  return a+b;
}

void Сумма(int a, int b, int & s)
{
  s= a+b;
}

Parameters of a function can be input - which we pass to it, and output - which it returns to us

 
ijonhson: int rates_total=Bars; int prev_calculated=0;

These variables are needed to calculate the whole indicator line, but you need a single value. Everything is much simpler. Analyse the indicator programme and determine which formula is used for calculation. And use this formula in the Expert Advisor

 

Guys, tell me how to implement this algorithm:

There is a time series with volume Volume

I want to compare Volume[1] to be larger than each of previous Volume[1] bars and specify a window (number) of previous bars with external variable (extern int)


Write a code sample, if it's not difficult

 
John Smith:

Guys, tell me how to implement this algorithm:

There is a time series with volume Volume

I want to compare Volume[1] to be larger than each of previous Volume[1] bars and specify a window (number) of previous bars with external variable (extern int)


Write a code sample, if it's not difficult

  for(int i=1; i<NumBar; i++) {
    ArrayResize(Buf, i);
    Buf[i-1] = Volume[i];
  }

 double min= Buf[ArrayMinimum(Buf)];
 double max= Buf[ArrayMaximum(Buf)];

 if(max < Volume[0]) { ... }
 
STARIJ:

Did it work? How did it work before?


It worked without errors, I seem to have removed it myself, by auto-replacement via ctrl+h, and didn't notice >_<. Anyway, it's probably the Illuminati that did it. Thanks again !

 
John Smith:

Guys, tell me how to implement this algorithm:

There is a time series with volume Volume

I want to compare Volume[1] to be larger than each of previous Volume[1] bars and specify a window (number) of previous bars with external variable (extern int)


Write a code sample, if it's not difficult

It's not difficult. I wrote it on my knees from memory (I may have missed something)...

//+------------------------------------------------------------------+
bool IsLastVolumeTheLargest(const string symbol_name, const ENUM_TIMEFRAMES timeframe,const int start_pos,const int count)
  {
   long array[];  // Массив для хранения объёмов
   //--- если скопировалось меньше, чем нужно, вернём false
   if(CopyTickVolume(symbol_name,timeframe,start_pos,count,array)<count) return false;
   //--- вернём флаг того, что максимальный объём находится в последней ячейке массива (соответствует индексу start_pos)
   return ArrayMaximum(array)==count-1;
  }
//+------------------------------------------------------------------+
 

Hello. I can't share the file. The task - I need the file of older period (e.g. M20) to be generated on М1 during manual testing in МТ4 (MQL4) tester. For this purpose I wrote an indicator based on the PeriodConverter script. Since in testing mode it is impossible to save the file (EURUSD20.csv) directly to the folder History, the file is saved in the folder shared by all terminals - \\MetaQuotes\Terminal\Common. Then the looped script, working on a standard M1 chart, copies data from the file EURUSD20.csv to the file EURUSD20.hst, located in the folder History. The file EURUSD20.csv cannot be opened in the script, if at the same time it is opened in the indicator in the tester (5004 ERR_FILE_CANNOT_OPEN File open error). If you remove the indicator from the tester, the file in the script is opened and copied without problems. The file is opened in the indicator as follows: ExtHandle=FileOpen(c_symbol+(string)20+".csv",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_COMMON);
The file in the script is opened as follows: ExtHandleR=FileOpen("EURUSD20.csv",FILE_BIN|FILE_READ|FILE_SHARE_READ);
Please indicate my mistake.

 
tvv:

Hello. I can't share the file. The task - I need the file of older period (e.g. M20) to be generated on М1 during manual testing in МТ4 (MQL4) tester. For this purpose I wrote an indicator based on the PeriodConverter script. Since in testing mode it is impossible to save the file (EURUSD20.csv) directly to the folder History, the file is saved in the folder shared by all terminals - \\MetaQuotes\Terminal\Common. Then the looped script, working on a standard M1 chart, copies data from the file EURUSD20.csv to the file EURUSD20.hst, located in the folder History. The file EURUSD20.csv cannot be opened in the script, if at the same time it is opened in the indicator in the tester (5004 ERR_FILE_CANNOT_OPEN File open error). If you remove the indicator from the tester, the file in the script is opened and copied without problems. File is opened in the indicator as follows: ExtHandle=FileOpen(c_symbol+(string)20+".csv",FILE_BIN|FILE_WRITE|FILE_SHARE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_COMMON);
File is opened in the script as follows: ExtHandleR=FileOpen("EURUSD20.csv",FILE_BIN|FILE_READ|FILE_SHARE_READ|FILE_COMMON);
Please point out my mistake.

Have you pointed it out?

 
Alexey Viktorov:

Did you specify it?

I don't get it. This option indicates the location of the file - \MetaQuotes\Terminal\Common. Without this option I won't be able to grab the file that was generated in the tester. Without this option the file will be searched in MQL4\Files - and I cannot put the file from the tester there.

Reason: