Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 583

 

Hello, help me out here. The trading robot, EA, Expert Advisor are not working. I downloaded everything possible and wanted to check how it all works. I thought my deposit was too small, but my demo account is the same. I thought I had a small deposit, but the same on a demo account.

 
Lilia.solomko:

Hello, help me out here. The trading robot, EA, Expert Advisor are not working. I downloaded everything possible and wanted to check how it all works. I thought my deposit was too small, but my demo account is the same. I thought my deposit was small but the same on my demo account.

How did you know that the robot did not trade? Did you make sure that all the conditions required by the trading strategy were fulfilled in order to open the position? Or did you just placed the robot and it did not immediately open the trade?

 
Lilia.solomko:

Hello, help me out here. The trading robot, EA, Expert Advisor are not working. I downloaded everything possible and wanted to check how it all works. I thought my deposit was too small, but my demo account is the same. I thought I had a small deposit but the same on a demo account.

I do not know what it says in the two tabs?


 
Please help me to write a function : close orders from a bigger lot to a smaller one (string Symbol, int type, bool hand orders, int Magic)
I.e. symbol selection, type, whether hand orders are taken into account, magic number.
 
Tigerfreerun:
Please help me to write a function : close orders from a bigger lot to a smaller one (string Symbol, int type, bool hand orders, int Magic)
I.e. symbol selection, type, whether the hand orders are taken into account, magic number.

Yes, it is ready to use.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 11.12.2008                                                     |
//|  Описание : Закрытие позиций в порядке сортировки по размерам лотов.       |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента        (    ""       - любой символ,      |
//|                                             NULL      - текущий символ)    |
//|    op - операция                        (    -1       - любая позиция)     |
//|    mn - MagicNumber                     (    -1       - любой магик)       |
//|    sd - Направление сортировки лотов    (MODE_ASCEND  - возрастание,       |
//|                                          MODE_DESCEND - убывание)          |
//+----------------------------------------------------------------------------+
void ClosePosBySortLots(string sy="", int op=-1, int mn=-1, int sd=MODE_DESCEND) {
  double a[][2];                  // Массив лотов и тикетов
  int    i, k=OrdersTotal();      // Счётчик и количество ордеров
  int    p=0;                     // Количество позиций

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
            p++;
            ArrayResize(a, p);
            a[p-1][0]=OrderLots();
            a[p-1][1]=OrderTicket();
          }
        }
      }
    }
  }

  // вдруг позиций нету, тогда и закрывать нечего
  if (p>0) {
    ArraySort(a, WHOLE_ARRAY, 0, sd);
    for (i=0; i<p; i++) {
      if (OrderSelect(a[i][1], SELECT_BY_TICKET)) {
        // проверим незакрытость на всякий случай,
        // может какая-то позиция уже закрылась по стопу/тейку
        if (OrderCloseTime()==0) ClosePosBySelect();
      }
    }
  }
}
 
Alekseu Fedotov:

Yes, it's ready to go.

Tried to use it, for some reason it doesn't work.
Where in this function is the closing itself, as far as I can see there is a reference to another function?
 
Tigerfreerun:
Tried to use it, for some reason it doesn't work.
Where is the closing itself in this function, as far as I can see there is a reference to another function?

Yes, there is a full-fledged ClosePosBySelect() function there, not just sending a trade order without status and result checks.

Search the site will give you a link to kim's ClosePosBySelect() function

 
Tigerfreerun:
Tried to use it, for some reason it doesn't work.
Where in this function is the closing itself, as far as I can see there is a reference to another function?

In the header of this function there is a website address, go download all the libraries,

It works just fine.

 

I draw horizontal bars. The indicator correctly, according to coordinates puts lines, but at some point, on a new bar a line is put on one, arbitrary price, consisting of many segments of different lengths, superimposed on each other. The price of setting "aliens" does not fit any condition. Where do they come from, how can they be prevented?

if(Line)
  {
   n_++;
   Setline(n_,Time[b_u_pbu],High[b_u_pbu],Time[b_u_pbu1],High[b_u_pbu],clrLime);
  }
//
void Setline(int sh,datetime tm,double pr,datetime tm1,double pr1,color clr)
  {
   ObjectCreate("-"+sh,OBJ_TREND,0,tm,pr,tm1,pr1,clr);
   ObjectSet("-"+sh,7,STYLE_SOLID);
   ObjectSet("-"+sh,10,false);
   ObjectSet("-"+sh,6,clr);
   ObjectSet("-"+sh,8,2);
  }
 
bij:

I draw horizontal bars. The indicator correctly, according to coordinates puts lines, but at some point, on a new bar a line is put on one, arbitrary price, consisting of many segments of different lengths, superimposed on each other. The "alien" setting price does not fit any condition. Where do they come from, how can they be prevented?

The names of the lines change and hence the multitude of lines.

In such cases it is best to include the opening time of the bar in the line name.

Reason: