[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 159

 

Dear, can you advise me?

There is Kim's feature "Closing a single position with maximum positive profit"

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Закрытие одной позиции с максимальным положительным профитом   |
//|             в валюте депозита                                              |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
void ClosePosWithMaxProfitInCurrency(string sy="", int op=-1, int mn=-1) {
  double pr=0;
  int    i, k=OrdersTotal(), np=-1;

  if (sy=="0") sy=Symbol();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (pr<OrderProfit()+OrderSwap()) {
            pr=OrderProfit()+OrderSwap();
            np=i;
          }
        }
      }
    }
  }
  if (np>=0) {
    if (OrderSelect(np, SELECT_BY_POS, MODE_TRADES)) {
      ClosePosBySelect();
    }
  }
}

https://forum.mql4.com/ru/38949/page2#434207

How to make this function close not only one position, but after closing one position with maximal profit it looks for the next one with maximal profit and passes it to close, etc.? ?

 
Sancho77:
...How can I make this function close not just one position, but after closing one position with maximum profit, it looks for the next position with maximum profit and passes it on to close, etc.? ?

And call it several times.
 
granit77:
And call her out a few times.
Got it, thanks!
 

Guys, I understand that the search rules and the topic was discussed a long time ago - so far I have found "hotkeys" on this topic(software launching of the script). Can anyone else share more links or solutions to the question: How to programmatically run erase.bat file of the client terminal directory ...\experts\files. I need this to clean it on a weekly basis and then fill it up, as I can't write new data in it over the past - I need to pre-prepare it. Thank you.

 
Xaoss1990:

This is the part of the code where we make the trade:

Why do you call closing an OrderClose() trade as setting a stop?

And it is interesting to know about the close variable? Is it global or local? But even if it is local, a bug will appear anyway. Where is this variable set to zero? Where is it set to one I see.

 
wolf05632:


This is the "WHATEVER"! Suppose a long mathematical expression. In VBA, let's say to split a long string into two, at any valid place of this string you need to put _

and the remaining expression can be added on a new line.

Example:

int a = 0;

equivalent to

int
a
=
1
;

Verstehen?

 
Moved:

eurodollar1981 09.09.2011 10:37
Hello! Can you tell me how to set up in mt4 to buy an order with a pre-set stoploss and take profit by pressing a single key?
 

Hi! Can you tell me how to remove the glitch on the chart in the form of a candle from the previous period, it is always drawn ahead and spoils all the indicators.Thank you.

 
korsar:

Hi! Can you tell me how to remove the glitch on the chart in the form of a candle from the previous period, it is always drawn ahead and spoils all the indicators.Thank you.

Personally, I don't understand anything...
 
MaxZ:

Example:

equivalent to

Verstehen?


Verstehen! Thank you! Now it remains to get an answer to my last post! And another question: what should the OBJ_TEXT time coordinate look like, so that the text is RIGHT of the zero candle?