[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 686

 

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?

 
Look for EAs codenamed Martingale.
 

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 can't put it into your EA yourself, right?
 
Roger:
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.
 
 
cyclik33:

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:

extern double Lot = 0.1

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:
if (isLossLastPos(NULL, -1, Magic))
   Lots_New *= 2;
else if (!isLossLastPos(NULL, -1, Magic))
   Lots_New = Lot;

The function itself, thanks to Igor Kim...

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. 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);
}
 

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:

//+------------------------------------------------------------------+
double getMartinLot(double lot, double x){         //ФУНКЦИЯ УПРАВЛЕНИЯ ОБъЕМОМ ТОРГОВ ПО СИСТЕМЕ МАРТИНГЕЙЛА
   static double balance_before, balance_after;    //ДЛЯ ХРАНЕНИЯ СОСТОЯНИЯ БАЛАНСА ДО И ПОСЛЕ СДЕЛОК
   static double 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.

Example of a function call:

if(OrdersTotal() == 0){
   OrderSend(Symbol(), OP_BUY, getMartinLot(0.1, 2), Ask, 10, Bid-25*Point, Bid+25*Point);
}
 
Does anyone know an indicator that returns several recent ZigZag extrema?