Here's another question. I have a trailing order. When 1 unidirectional order is open, everything works fine, if more, it doesn't work for some reason. Why?
Here's the .cpp file of the project, have a look at it and after a couple of Google and Yandex searches, I didn't find anything at all brainy, it's generally understandable. It even seems simple.
But how does it work? I'm not quite sure how to refer to this ddl - from the EA's code? How? First, it looks like this #include <GetIntValue>.
It's roughly like this. To make it work, you need to compile the dll and put it in the experts/libraries folder (read the help and tutorial, it's detailed there).
//сначала надо объявить импорт функции из DLL#import "имя_вашей_длл.dll"int SortStringArray(string *arr[],constint arraysize);
#import
//в тексте программы вызов проще простогоstring arr[];
int size;
...
//где-то в коде массив заполняется
...
//а вот и вызов сортировки
SortStringArray(arr,size);
2. When calling the dll, you don't have to keep studio on, right? So how is it executed?
A DLL is, to put it simply, a normal Windows program, except that the functions it implements are not called by a user, but by another program. To make it possible, we specify __declspec(dllexport) modifier to C++ compiler.
Here's another question. I have a trailing order. When 1 unidirectional order is open, everything works fine, if more, it doesn't work for some reason. Why?
In your opinion, should I add to the error handling function in this EA a check for 129 and 138 errors?
If yes, how to do it?
At a minimum, you must have your own function for opening positions/setting orders that will handle all errors. This is where you need to get the latest prices.
I haven't looked at any blanks. But I will say: the EA needs to handle all the errors returned by the server. And that's not enough. It should be able to pick up its positions after any unexpected situation without loss of functionality and without the algorithm failure, and continue its work as if nothing extraordinary had happened.
compile it and put it in the experts/libraries folder Here you go, thanks!!! I'll try it now. And I've seen it before, but now I do not find anything so detailed and digestible on the subject.
At the very least you should have your own function for opening positions/setting orders that handles all errors. It is where you need to get the latest prices.
I haven't looked at any blueprints. But I will say: you need to handle all errors returned by the server in your EA. And this is not enough. It must be able to pick up its positions after any unforeseen situation, without losing functionality, without any failure of its algorithm, and continue its work as if nothing extraordinary had happened.
The template is taken from a textbook. I'm not really good at error handling functions.
On order opening, there is RefreshRates(); (I replaced Bids and Asks through Market Info as suggested).
while(true) // Цикл закрытия орд.
{
if (Total==0 && Opn_B==true) // Открытых орд. нет +
{ // критерий откр. Buy
RefreshRates(); // Обновление данных
SL=Bid - New_Stop(StopLoss)*Point; // Вычисление SL откр.
TP=Bid + New_Stop(TakeProfit)*Point; // Вычисление TP откр.Alert("Попытка открыть Buy. Ожидание ответа..");
Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP);//Открытие Buyif (Ticket > 0) // Получилось :)
{
Alert ("Открыт ордер Buy ",Ticket);
return; // Выход из start()
}
if (Fun_Error(GetLastError())==1) // Обработка ошибокcontinue; // Повторная попыткаreturn; // Выход из start()
}
And error handling function:
int Fun_Error(int Error) // Ф-ия обработ ошибок
{
switch(Error)
{ // Преодолимые ошибки case4: Alert("Торговый сервер занят. Пробуем ещё раз..");
Sleep(3000); // Простое решениеreturn(1); // Выход из функцииcase135:Alert("Цена изменилась. Пробуем ещё раз..");
RefreshRates(); // Обновим данныеreturn(1); // Выход из функцииcase136:Alert("Нет цен. Ждём новый тик..");
while(RefreshRates()==false) // До нового тикаSleep(1); // Задержка в циклеreturn(1); // Выход из функцииcase137:Alert("Брокер занят. Пробуем ещё раз..");
Sleep(3000); // Простое решениеreturn(1); // Выход из функцииcase146:Alert("Подсистема торговли занята. Пробуем ещё..");
Sleep(500); // Простое решениеreturn(1); // Выход из функции// Критические ошибкиcase2: Alert("Общая ошибка.");
return(0); // Выход из функцииcase5: Alert("Старая версия терминала.");
Work=false; // Больше не работатьreturn(0); // Выход из функцииcase64: Alert("Счет заблокирован.");
Work=false; // Больше не работатьreturn(0); // Выход из функцииcase133:Alert("Торговля запрещена.");
return(0); // Выход из функцииcase134:Alert("Недостаточно денег для совершения операции.");
return(0); // Выход из функцииdefault: Alert("Возникла ошибка ",Error); // Другие варианты return(0); // Выход из функции
}
}
I wanted to ask. I want to ask: May I add another line from 129 error to it?
case129:Alert("Неправильные цены. Пробуем ещё раз..");
RefreshRates(); // Обновим данныеreturn(1);
I have the entire visual studio project in my experts folder... Compile is an .exe file, right? I wanted to copy it to the libarries folder... I can't find it! Here's the debug folder of the project. I'm sorry, it's a new topic.
I don't get it here...
The lot size should increase exponentially (with multiplier 2) if a second unidirectional order is opened.
This is the result.
then like this
you get a result like this
Then that's it.
Thanks, I get the idea... I've got it figured out.
what is that line for?
datetime o;Here's another question. I have a trailing order. When 1 unidirectional order is open, everything works fine, if more, it doesn't work for some reason. Why?
{
for(int i = 0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if (OrderType() == OP_BUY)
{
if(Bid - OrderOpenPrice() > TrailingStop*Point)
{
if (OrderStopLoss() < Bid - (TrailingStop + TrailingStep)*Point)
{
SL = NormalizeDouble(Bid - TrailingStop*Point,Digits);
if (OrderStopLoss() !=SL)
OrderModify(OrderTicket(),OrderOpenPrice(),SL,0,0);
}
}
}
if (OrderType() == OP_SELL)
{
if(OrderOpenPrice() - Ask > TrailingStop*Point)
{
if (OrderStopLoss() > Ask + (TrailingStop+ TrailingStep)*Point)
{
SL = NormalizeDouble (Ask+TrailingStop*Point,Digits);
if (OrderStopLoss() !=SL)
OrderModify (OrderTicket(), OrderOpenPrice(), SL,0,0);
}
}
}
}
}
}
}
Here's the .cpp file of the project, have a look at it and after a couple of Google and Yandex searches, I didn't find anything at all brainy, it's generally understandable. It even seems simple.
But how does it work? I'm not quite sure how to refer to this ddl - from the EA's code? How? First, it looks like this #include <GetIntValue>.
It's roughly like this. To make it work, you need to compile the dll and put it in the experts/libraries folder (read the help and tutorial, it's detailed there).
2. When calling the dll, you don't have to keep studio on, right? So how is it executed?
Here's another question. I have a trailing order. When 1 unidirectional order is open, everything works fine, if more, it doesn't work for some reason. Why?
{
for(int i = 0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if (OrderType() == OP_BUY)
{
if(Bid - OrderOpenPrice() > TrailingStop*Point)
{
if (OrderStopLoss() < Bid - (TrailingStop + TrailingStep)*Point)
{
SL = NormalizeDouble(Bid - TrailingStop*Point,Digits);
if (OrderStopLoss() !=SL)
OrderModify(OrderTicket(),OrderOpenPrice(),SL,0,0);
}
}
}
if (OrderType() == OP_SELL)
{
if(OrderOpenPrice() - Ask > TrailingStop*Point)
{
if (OrderStopLoss() > Ask + (TrailingStop+ TrailingStep)*Point)
{
SL = NormalizeDouble (Ask+TrailingStop*Point,Digits);
if (OrderStopLoss() !=SL)
OrderModify (OrderTicket(), OrderOpenPrice(), SL,0,0);
}
}
}
}
}
}
}
Because you need to pass parameters into the function, try this
bool IfProfTrail=false; // Use only for profitable positions - Breakeven mode
int TrailingStop=0; // Trailing distance = 0 - minimum allowed
int TrailingStep=1; // Trailing distance step
Thank you very much!
Now I understand what the problem is.
For the purchase I used:
As far as I know, buying is ask, but iClose(Symbol(),Period(),0) takes prices from bid. This may be the reason for error.
But here the question arises, because the EA is not a Pips based EA, the price was in the buy zone for a long time and updated with every tick.Now I use the following combination:
Why does not the trade open? It turns out that the EA stops on the error and does not see further price movement?
I took the template for my Expert Advisor from https://c.mql5.com/mql4/book/mq4/experts/tradingexpert.mq4
In your opinion, should I add to the error handling function in this EA a check for 129 and 138 errors?
If yes, how to do it?
At a minimum, you must have your own function for opening positions/setting orders that will handle all errors. This is where you need to get the latest prices.
I haven't looked at any blanks. But I will say: the EA needs to handle all the errors returned by the server. And that's not enough. It should be able to pick up its positions after any unexpected situation without loss of functionality and without the algorithm failure, and continue its work as if nothing extraordinary had happened.
At the very least you should have your own function for opening positions/setting orders that handles all errors. It is where you need to get the latest prices.
I haven't looked at any blueprints. But I will say: you need to handle all errors returned by the server in your EA. And this is not enough. It must be able to pick up its positions after any unforeseen situation, without losing functionality, without any failure of its algorithm, and continue its work as if nothing extraordinary had happened.
The template is taken from a textbook. I'm not really good at error handling functions.
On order opening, there is RefreshRates(); (I replaced Bids and Asks through Market Info as suggested).
And error handling function:
I wanted to ask. I want to ask: May I add another line from 129 error to it?