Please tell me what to insert (and where to insert it, if possible) in the code to make the EA open a position with the previous lot multiplied by 2 if the previous trade was losing.
Thank you very much.
I just want to ask you a question: What should I do if I want to open a position with this EA?
//+----------------------------------------------------------------------------+//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |//+----------------------------------------------------------------------------+//| Версия : 19.02.2008 |//| Описание : Возвращает флаг убыточности последней позиции. |//+----------------------------------------------------------------------------+//| Параметры: |//| sy - наименование инструмента ("" - любой символ, |//| NULL - текущий символ) |//| op - операция (-1 - любая позиция) |//| mn - MagicNumber (-1 - любой магик) |//+----------------------------------------------------------------------------+bool isLossLastPos(string sy="", int op=-1, int mn=-1) {
datetime t;
int i, j=-1, k=OrdersHistoryTotal();
if (sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderSymbol()==sy || sy=="") {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderCloseTime()) {
t=OrderCloseTime();
j=i;
}
}
}
}
}
}
}
if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderProfit()<0) return(True);
}
return(False);
}
Dear programmers. Please, advise me what to insert (and where to insert it if possible) in the code to make the EA open a position with the previous lot multiplied by 2, if the previous trade was losing. I thank you in advance. Boris.
Boris, it's not hard at all, here's a simple function that implements the martingale principle:
//+------------------------------------------------------------------+double getMartinLot(double lot, double x){ //ФУНКЦИЯ УПРАВЛЕНИЯ ОБъЕМОМ ТОРГОВ ПО СИСТЕМЕ МАРТИНГЕЙЛАstaticdouble balance_before, balance_after; //ДЛЯ ХРАНЕНИЯ СОСТОЯНИЯ БАЛАНСА ДО И ПОСЛЕ СДЕЛОКstaticdouble save_Lot;
balance_after = AccountBalance(); //СОХРАНЕНИЕ ТЕКУЩЕГО СОСТОЯНИЯ БАЛАНСАif(balance_after >= balance_before){ //ПРОВЕРКА ИЗМЕНЕНИЯ БАЛАНСА
save_Lot = lot; //ЕСЛИ ОН НЕ ИЗМЕНИЛСЯ ИЛИ СТАЛ БОЛЬШЕ, ТО СБРАСЫВАЕМ ЛОТ ДО БАЗОВОГО
}else{
save_Lot *= x; //ЕСЛИ СТАЛ МЕНЬШЕ ТО УВЕЛИЧИВАЕМ ЛОТ НА Х РАЗ
}
balance_before = balance_after; //СОХРАНЯЕМ СОСТОЯНИЕ БАЛАНСА ПОСЛЕ РАБОТЫreturn(save_Lot);
}
//+------------------------------------------------------------------+
Pass the initial volume(double lot), and the step(double x) as parameters. Insert the method directly into OrderSend instead of the volume parameter.
itum:
How to solve this problem ? Ga
Do condition handling only once at the beginning of the bar.
Alternatively, run a flag that is set if an order is placed and reset when conditions have changed significantly.
Уважаемые програмисты.
Please tell me what to insert (and where to insert it, if possible) in the code to make the EA open a position with the previous lot multiplied by 2 if the previous trade was losing.
Thank you very much.
I just want to ask you a question: What should I do if I want to open a position with this EA?
Roger:
Ищите советники с кодовым названием Мартингейл.
I've been looking for one but it doesn't work for me.
I found one that should double a lot if a previous trade was losing, but it does not want to work.
This probably means that if you are offered code here, you still won't be able to insert it into your EA yourself, right?
No, it means that the EA was not working, and I cannot find a working one with the piece of code I need.
Check it out, https://www.mql5.com/ru/forum/104481
No, it means that the EA was not working, and I can't find a working one with the piece of code I need.
In the global variables set the initial value of the lot:
There we assign this value to the variable, which will pass the lot value to the position opening function:
double Lots_New = Lot;After closing the position, let's check it for profit/loss:The function itself, thanks to Igor Kim...
cyclik33:
Dear programmers.Please, advise me what to insert (and where to insert it if possible) in the code to make the EA open a position with the previous lot multiplied by 2, if the previous trade was losing.
I thank you in advance.
Boris.
Boris, it's not hard at all, here's a simple function that implements the martingale principle:
Pass the initial volume(double lot), and the step(double x) as parameters.
Insert the method directly into OrderSend instead of the volume parameter.
Example of a function call: