int gtc1 = GetTickCount();
res_copy_buf = CopyBuffer(handle, 0, 0, bars_calc, Buf_01);
int gtc2 = GetTickCount();
All symbols pass normally. During the first pass the time is about 120ms, because indicator buffers are filling. Starting with second pass time of calculation on current bar is less than 1 ms.
Peculiarity is that one well-known broker has EURRUR symbol, for which there is no data ("Wait for update"). Therefore the calculation is stuck on this line for 51 seconds. Error 4806. 51 seconds is unacceptable even for one (first) time, let alone a cycle.
Question. How do I quickly find out the fact that there is no data for a given character? I would then memorize it and on subsequent iterations just step over it and go on without losing pace.
Colleagues, please advise how to convert an array of type double to string. I need to write it to a file. Here is a general training code.
voidOnStart()
{
double ar[]; // МассивArrayResize(ar,2); // Подготовка массиваint i, Size=ArraySize(ar); // стартовое количество элементов
ar[0]=1; // Установка значений 2-х элементов массива
ar[1]=2;
ArrayResize(ar,3); // Увеличение размера массива
ar[2]=3; // Установка значения новому элементу массиваArrayResize(ar,4); // Увеличение размера массива
ar[3]=4; // Установка значения новому элементу массиваArrayResize(ar,5); // Увеличение размера массива
ar[4]=5; // Установка значения новому элементу массиваArrayResize(ar,6); // Увеличение размера массива
ar[5]=6; // Установка значения новому элементу массивArrayResize(ar,7); // Увеличение размера массива
ar[6]=7; // Установка значения новому элементу массив
Size=ArraySize(ar);// новое количество элементовArraySetAsSeries(ar,true); // Смена направления индексации//--- запись в файл
SaveArrayToFile ("s_ar", ar);
return;
}
bool SaveArrayToFile(string FileName, string &Array[])
{
//--- Открытие файлаint h=FileOpen(FileName,FILE_WRITE|FILE_ANSI|FILE_TXT);
if(h==-1){Alert(" ошибка открытия файла в ф-ии "); return(false);} // Ошибка открытия файла//--- Запись в файлFileWriteInteger(h,ArraySize(Array),INT_VALUE); // Запись размера массиваFileWriteArray(h,Array); // Запись массива//--- Закрытие файлаFileClose(h);
return(true); // Сохранение выполнено
When saving and loading an array from a file, we should consider the difference in the first dimension of the array's size and the total number of its elements. When you save an array, you should first write the size of the array (the total number of elements determined by ArraySize()) into the file, then the entire array:
bool SaveArrayToFile(string FileName,string &Array[])
{
//--- Открытие файлаint h=FileOpen(FileName,FILE_TXT|FILE_WRITE);
if(h==-1) return(false); // Ошибка открытия файла//--- Запись в файлFileWriteInteger(h,ArraySize(Array),INT_VALUE); // Запись размера массиваFileWriteArray(h,Array); // Запись массива//--- Закрытие файлаFileClose(h);
return(true); // Сохранение выполнено
}
I have two EAs for the same instrument with different magiks respectively. I set my magik through CTrade and open a position through CTrade too. When I have an open position of the first EA, its magik is assigned to the second EA (I checked it after opening a position, see below), so the check for open positions does not see my magik and open many positions in the same direction. The account is on a demo, this cannot be detected in the tester. If the value of the magik is saved in the class, maybe it should be zeroed, but I don't know how.
intOnInit()
{
// выставляем магик
m_trade.SetExpertMagicNumber(Magic);
return(INIT_SUCCEEDED);
}
открываю позицию соответственно тоже через CTrade:
if(SellCount()>0 || BuyCount()>0)
{
Print("Уже есть позиция на продажу !!!");
return; // не добавлять к открытой позиции на покупку
}
SL=NormalizeDouble(latest_price.bid + STP*_Point,_Digits);
TP=NormalizeDouble(latest_price.bid - TKP*_Point,_Digits);
m_trade.Sell(lots1,_Symbol,0,SL,TP,"LaquerreOSC_MA_2.5.6.7 + 2");
m_position.Select(_Symbol);
{
ulong myMagic=m_position.Magic();
Print(" Открыта поза Селл с магиком № ",myMagic,", И спредом ",SymbolInfoInteger(_Symbol,SYMBOL_SPREAD));
}
//+------------------------------------------------------------------+int SellCount()//проверка рыночных ордеров на продажу
{
int count=0;
for(int i=PositionsTotal()-1; i>=0;i--)
{
if(PositionSelect(_Symbol)==true)
{
if(PositionGetInteger(POSITION_MAGIC)==Magic && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
I have two EAs for the same instrument with different magiks respectively. I set my magik through CTrade and open a position through CTrade too. When I have an open position of the first EA, its magik is assigned to the second EA (I checked it after opening a position, see below), so the check for open positions does not see my magik and I open many positions in one direction. The account is on a demo, this cannot be detected in the tester. If the value of the magik is saved in the class, maybe it needs to be zeroed, but I don't know how.
As for the code: set the input parameters to each EA with its own magic. Suppose you set the first one to 10001, then the second one to 10002.
Thank you for such a short answer. But that is the point, the magics are different. Thus, I have determined that the second robot opens positions with the first magician. I do not know how it happens and where he saves the first EA's magic number but I would like to find out.
Thanks for the quick response. But that's the thing, the magicians are different. So I found out that the second robot is opening positions with the first one's magic number. I do not know how it happens and where he saves the first magician number but I would like to find out.
In this case, it's not "better", it's exactly what you need - it's a wrapper class for standard trading functions. It does not store multiple magiks. That's why it should be set a magik every time before and when you want to open a position with a new magik.
Generally the sequence is as follows:
positions should be opened with magic 1 - we set magic 1 and subsequent positions will have magic 1,
it is necessary to open positions with a Magician 2 - we set up Magician 2 and all following positions will have a Magician 2,
it is necessary to open positions with magic 3 - we will set up magic 3 and every next position will have magic 3,
Originally it was like this, it doesn't help. But in examples it is usually in OnInit so has moved. For a long time I've been messing around with this, owls on the test seem to be running smoothly, then suddenly I open the server and there are 20 positions in one direction. Can the fact that the check for open positions is not through classes?
Thanks for the quick response. But that's the thing, the magicians are different. So I found out that the second robot is opening positions with the first one's magic number. I don't know how it happens and where he saves first EA's magic number but I want to find out.
Since there is noGetExpertMagicNumber method in CTrade class, please print this code after the trade operation:
The multi-currency expert in the loop asks for data by symbol. There is such a fragment:
All symbols pass normally. During the first pass the time is about 120ms, because indicator buffers are filling. Starting with second pass time of calculation on current bar is less than 1 ms.
Peculiarity is that one well-known broker has EURRUR symbol, for which there is no data ("Wait for update"). Therefore the calculation is stuck on this line for 51 seconds. Error 4806. 51 seconds is unacceptable even for one (first) time, let alone a cycle.
Question. How do I quickly find out the fact that there is no data for a given character? I would then memorize it and on subsequent iterations just step over it and go on without losing pace.
Colleagues, please advise how to convert an array of type double to string. I need to write it to a file. Here is a general training code.
Info taken from article
Saving and loading arrays from a file
When saving and loading an array from a file, we should consider the difference in the first dimension of the array's size and the total number of its elements. When you save an array, you should first write the size of the array (the total number of elements determined by ArraySize()) into the file, then the entire array:
Hello, I am facing the following problem.
I have two EAs for the same instrument with different magiks respectively. I set my magik through CTrade and open a position through CTrade too. When I have an open position of the first EA, its magik is assigned to the second EA (I checked it after opening a position, see below), so the check for open positions does not see my magik and open many positions in the same direction. The account is on a demo, this cannot be detected in the tester. If the value of the magik is saved in the class, maybe it should be zeroed, but I don't know how.
Hello, I am facing the following problem.
I have two EAs for the same instrument with different magiks respectively. I set my magik through CTrade and open a position through CTrade too. When I have an open position of the first EA, its magik is assigned to the second EA (I checked it after opening a position, see below), so the check for open positions does not see my magik and I open many positions in one direction. The account is on a demo, this cannot be detected in the tester. If the value of the magik is saved in the class, maybe it needs to be zeroed, but I don't know how.
Pleasepaste the code correctly, not as a sheet of text.
As for the code: set the input parameters to each EA with its own magik. Let's say you set the first one to 10001, then the second one to 10002.
Pleaseinsert the code correctly, not as a sheet of text.
As for the code: set the input parameters to each EA with its own magic. Suppose you set the first one to 10001, then the second one to 10002.
Thank you for such a short answer. But that is the point, the magics are different. Thus, I have determined that the second robot opens positions with the first magician. I do not know how it happens and where he saves the first EA's magic number but I would like to find out.
Thanks for the quick response. But that's the thing, the magicians are different. So I found out that the second robot is opening positions with the first one's magic number. I do not know how it happens and where he saves the first magician number but I would like to find out.
In this case, it is better to set the magik
// выставляем магик m_trade.SetExpertMagicNumber(Magic);before every opening of position /order instead of in OnInit.In this case, it is better to specify a magik
before each opening of position, not in OnInit.In this case, it's not "better", it's exactly what you need - it's a wrapper class for standard trading functions. It does not store multiple magiks. That's why it should be set a magik every time before and when you want to open a position with a new magik.
Generally the sequence is as follows:
etc...
In this case, it's better to set a magik
Before each opening of a position/order, and not in OnInit.Originally it was like this, it doesn't help. But in examples it is usually in OnInit so has moved. For a long time I've been messing around with this, owls on the test seem to be running smoothly, then suddenly I open the server and there are 20 positions in one direction. Can the fact that the check for open positions is not through classes?
Thanks for the quick response. But that's the thing, the magicians are different. So I found out that the second robot is opening positions with the first one's magic number. I don't know how it happens and where he saves first EA's magic number but I want to find out.
Since there is noGetExpertMagicNumber method in CTrade class, please print this code after the trade operation:
This way you can check if both EAs have different magics.