Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1117

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
string path=InpDirectoryName+"//"+InpFileName;
//--- откроем файл
ResetLastError();
int file_handle=FileOpen(path,FILE_READ|FILE_BIN);
if(file_handle!=INVALID_HANDLE)
{
//--- прочитаем все данные из файла в массив
FileReadArray(file_handle,arr);
//--- получим размер массива
int size=ArraySize(arr);
//--- распечатаем данные из массива
Print(" = ",arr[0][0]," = ",arr[1][1]," = ",arr[2][2]);
Print("Total data = ",size);
//--- закрываем файл
FileClose(file_handle);
}
else
Print("File open failed, error ",GetLastError());
2017.01.09 17:20:40.609 TorFid_v02 (EURUSD,H1) Total data = 1020100
I understand what's missing, the reverse conversion to a 2D array, but I don't understand how
Unless, of course, I saved it correctly.
{
for(int q=1; q<ARRAY_SIZE_X-1; q++) // Перебор по периоду, колонка X
{
arr[q][z]=NormalizeDouble(sm.d[q+1].m[nBar-z],5); // M(I) SMA
}
}
WriteData(1000);
//| Запись n элементов массива в файл |
//+------------------------------------------------------------------+
void WriteData(const int n)
{
//--- откроем файл
ResetLastError();
int handle=FileOpen(path,FILE_READ|FILE_WRITE|FILE_BIN);
if(handle!=INVALID_HANDLE)
{
//--- запишем данные массива в конец файла
FileSeek(handle,0,SEEK_END);
FileWriteArray(handle,arr,0,n);
//--- закрываем файл
FileClose(handle);
}
else
Print("Failed to open the file, error ",GetLastError());
}
I hope those lines are present, too.
input string InpFileName="data.bin";
input string InpDirectoryName="SomeFolder";
Start with an easy one. Write the whole thing into scripts. One to write the file and one to read and print what you read. For writing, make a simple 2x2 array
void OnStart()
{
int z = 0;
for(int i = 0; i < 2; i++)
{
arr[i][z] = i+z+1;
z++;
}
WriteData();
}
and remove the number of elements you want to write. This way the whole file will be written from start to finish. Check if the file appears in the given path.
FileWriteArray(handle,arr); // и здесь
Here's what you get.
Write script code.
//| WriteArray.mq5 |
//| Viktorov |
//| v4forex@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Viktorov"
#property link "v4forex@yandex.ru"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
string InpFileName = "data.bin";
string InpDirectoryName = "SomeFolder";
string path=InpDirectoryName+"//"+InpFileName;
int arr[3][3];
int handle;
void OnStart()
{
int i = 0, z = 0;
for(i = 0; i < 3; i++)
{
for(z = 0; z < 3; z++)
{
arr[i][z] = i*z+1;
}
}
WriteData();
}
//+------------------------------------------------------------------+
void WriteData()
{
//--- откроем файл
ResetLastError();
handle=FileOpen(path, FILE_READ|FILE_WRITE|FILE_BIN);
if(handle!=INVALID_HANDLE)
{
//--- запишем данные массива в конец файла
FileSeek(handle,0,SEEK_END);
FileWriteArray(handle,arr);
//--- закрываем файл
FileClose(handle);
}
else
Print("Failed to open the file, error ",GetLastError());
}
Read script code.
//| ReadArray.mq5 |
//| Viktorov |
//| v4forex@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Viktorov"
#property link "v4forex@yandex.ru"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
string InpFileName = "data.bin";
string InpDirectoryName = "SomeFolder";
string path=InpDirectoryName+"//"+InpFileName;
int handle;
void OnStart()
{
int arr[3][3];
int i = 0, z = 0;
handle = FileOpen(path, FILE_READ|FILE_WRITE|FILE_BIN);
FileReadArray(handle, arr);
for(i = 0; i < 3; i++)
{
for(z = 0; z < 3; z++)
{
Print("arr[", i, "][", z, "]", arr[i][z]);
}
}
}
//+------------------------------------------------------------------+
and this is what's printed.
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[0][1]1
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[0][2]1
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[1][0]1
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[1][1]2
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[1][2]3
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[2][0]1
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[2][1]3
2017.01.09 12:46:22.979 ReadArray (EURUSD,M1) arr[2][2]5
So you don't need any conversion gimmicks. You only need to set the same arrays from the beginning.
Don't mind that it's mql5, the same way it would work in mql4.
Then read and print out what you got. If you see 1 and 3 it means the problem is in filling the array.
Honestly don't even know what happened, but it all worked, I just have to add a line every new bar, hopefully there won't be any questions)))
Thank you!
Hi all!!! Please advise me, I want to download a clean MT4, but can not find anywhere, from the off site pumps only MT5. Please give me the latest build. Thanks a lot!!!
Hi all!!! Please advise me, I want to download a clean MT4, but can not find anywhere, from the off site pumps only MT5. Please give me the latest build. Thanks a lot!!!
Your only difference is the logo in the shortcut.
Open an account in another brokerage company. Or another type of account. Whether or not a marketplace is available depends entirely on the account
Open an account in another brokerage company. Or another type of account. If the market does not work, it depends on the account.
Tried three DCs and different accounts, the market still doesn't work(
Please advise on possible developments.
I have array[100], also saved binary file with size [1000], how to return array of binary file last 100 values. Is there anything universal? I've been working on this again for 12 hours and nothing.