Questions from Beginners MQL4 MT4 MetaTrader 4 - page 154

 
nidves firstly, make a correct message with the code, it's very difficult to understand it, and secondly, I would like to see the structure of the news file, otherwise it's not clear what data is used where.
 

The first thing that catches your eye is that you are using the EA as an ordinary script. Read the manual to see how they are different. It is the script, not the Expert Advisor, that is suitable for your task!

Second,why do you use this design?

  for (count=1; count<=countstr; count++)
  {
   //----
   //----  
  if (count>=countstr) break;
  }

And the root of your problem.

void CreatFile()
   {
    string Filepatch="Analyse news\\"+"Symbol"+"_"+IntegerToString(periodMT)+".csv";
    Comment("Creat a new file");
    int file=FileOpen(Filepatch, FILE_WRITE|FILE_CSV);
    FileWrite(file, "Symbol","Period","News","Data Time","Open","High","Low","Close");
    
    int  bar_index=iBarShift(symbolMT,periodMT,DateNews[count-1]); 
//Чему равен в этот момент count? 
//Для чего нужен был массив событий если в обработку попадает только одно событие?
//Функция iBarShift (так как вы используете) возвращает либо номер бара по времени либо ближайший номер бара если в истории есть пропуски 
//Внимательно почитайте описание 
    int  countBar=bar_index;
    
    for(count=1; count<=countstr; count++)
    {
    countBar--;
    
    FileWrite(file,symbolMT,periodMT,NameNews[count-1],DateNews[count-1],
    
    DoubleToStr(iOpen(symbolMT,periodMT,countBar))

    );
    }
    FileClose(file);
    ExpertRemove();
   }

Well, the last you have very much messed up in a simple program describe what you want from this program and let's try to write the script step by step nicely!

 
Vitaly Gorbunov:

The first thing that catches your eye is that you are using the EA as an ordinary script. Read the manual to see how they are different. It is the script, not the Expert Advisor, that is suitable for your task!

Second,why do you use this design?

And the root of your problem.

And finally, you are making too much noise in a simple program, describe what you want from this program and let's try to write the script step by step!

Vitaly, thank you for your reply!

1)About the script, I understand you, I'll try.

2)Well, everything is simple, I interrupt the for loop.

3) I want to create an Expert Advisor or a script that will download quotes for certain instruments + timeframes, specific news by specific date and time.

The final result of writing to the file should look like this

SymbolPeriodNewsDateTimeOpenHighLowClose
GBPUSD5Canada'sbenchmark consumer price index (CPI) (m/m)26.01.2018 16:30:000.000000000.000000000.000000000.00000000
GBPUSD5Canada's benchmark consumer price index (CPI) (m/m)21.12.2017 15:30:000.000000000.000000000.000000000.00000000
GBPUSD5Canada's benchmark consumer price index (CPI) (m/m)17.11.2017 15:30:000.000000000.000000000.000000000.00000000
GBPUSD5Canada's benchmark consumer price index (CPI) (m/m)20.10.2017 15:30:000.000000000.000000000.000000000.00000000

And so on different instruments+timeframes+newsand dates.

There is one more nuance. If the data is unloaded on the 60 minute timeframe, then the quotes should correspond to the 16:00 and 15:00 timeframes.

If the news timeframe is 14:45, then the quotes should correspond to the time:

1 minute - 14:45

5 minutes - 14:45

15 minutes - 14:45

30 minutes - 14:30

60 minutes - 14:00

I hope I made myself clear. Thank you

 

Look at this loop again! The variable count is only changed by the for statement itself, so if is just superfluous in this loop.

Let's now define how we will process the data. It seems to me that it would be more logical to read from the news file the news parameters, process the data and write them into the file of quotes. Collecting an array of news that then have to run through an array again for one record does not seem rational, in addition, very often in the processing of arrays can make a lot of errors associated with indexes.

 
Vitaly Gorbunov:

Look at this loop again! The variable count is only changed by the for statement itself, so if is just superfluous in this loop.

Let's now define how we will process the data. It seems to me that it would be more logical to read from the news file the news parameters, process the data and write them into the file of quotes. Collect an array of news, that then again to run through an array for one record does not seem rational, in addition, very often in the processing of arrays can make a lot of errors associated with indexes.

I mean, create files with quotes in advance and add news parameters to the file?

 
nidves:

You mean create the quote files in advance and add the news parameters to the file?

You don't understand me, we read from the news file, process it and immediately write it into the quote file and so on until the whole news file is processed!
 
Vitaly Gorbunov:
You don't understand me, we read from the news file, process it and immediately write it into the quote file and so on until the whole news file is processed!
That's what I'm trying to do, only through arrays. How would you write this code?
 
nidves:
That's what I'm trying to do, only through arrays. How would you write such code?
Why use an array where it's not needed? The simpler the code, the fewer mistakes you can make!
 
Vitaly Gorbunov:
Why should I use the array where it's not needed? The simpler the code, the fewer errors you can make!

I'm learning to work with arrays through this code. After all, the task is not complicated in principle.

OpenSymbol  [count-1]=iOpen(symbolMT,periodMT,numberBar);

The "Open" quotes are already stored in the array above. Therefore, I need just to pull out the quote of the date I need from the array.

 
nidves:

I am learning to work with arrays through this code. After all, the task is not complicated in principle.

The "Open" quotes are already stored in the array above. Therefore, I just need to pull the quote of the date I need from this array.

I'm going to summer now and will be there on Monday. If you're interested, add me as a friend and we'll chat without littering the forum.
Reason: