Useful features from KimIV - page 121

 

There is an error in the function https://forum.mql4.com/ru/38949/page5#434241.

It should be like this

double PriceOpenNearPos(string sy="", int op=-1, int mn=-1) {
  double mi, oop=0, p;
  int    i, k=OrdersTotal(), pp=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) {
            if (OrderType()==OP_BUY)  mi=MarketInfo(OrderSymbol(), MODE_ASK);
            if (OrderType()==OP_SELL) mi=MarketInfo(OrderSymbol(), MODE_BID);
            p=MarketInfo(OrderSymbol(), MODE_POINT);
            if (p==0) if (StringFind(sy, "JPY")<0) p=0.0001; else p=0.01;
            if (pp==0 || pp>MathAbs(OrderOpenPrice()-mi)/p) {
              pp=MathAbs(OrderOpenPrice()-mi)/p;
              oop=OrderOpenPrice();
              if(pp==0) break;
            }
          }
        }
      }
    }
  }
  return(oop); 

}

Please re-download.

 

Good afternoon everyone!

When fixing Expert Advisors (due to MQL updates) it turned out that many of Igor Kim's functions do not work anymore. This includes the most popular ones. For example,

NumberOfPositions - Returns the number of positions.

ExistPositions - Returns the flag of existence of positions.

Another function, I mentioned yesterday in the thread: Function NumberOfBarCloseLastPos().
This function returns the number of bar to close the last position

When I display the comment on the Strategy Tester chart, I see that the functions return constant values (-1 and/or 0) all the time, despite the existence of trades (current and closed). It looks like the EA does not see the conditions defined by these functions in its code.

In addition, the so-called "executable" functions stop working, e.g., a set of functions for closing positions: ClosePosBySelect (this function closes one preliminarily selected position) and associated functions:
ClosePositions - Close positions at market price, etc.

Please advise what kind of bugs are in these functions and what has to be fixed, at least using one of them -NumberOfPositions - it returns the number of positions?

 
Rita:

Good afternoon everyone!

When fixing Expert Advisors (due to MQL updates) it turned out that many of Igor Kim's functions do not work anymore. This includes the most popular ones. For example,

NumberOfPositions - Returns the number of positions.

ExistPositions - Returns the flag of existence of positions.

Another function, I mentioned in the branch yesterday: Function NumberOfBarCloseLastPos().
This function returns the number of bar to close the last position.

When I display the comment on the Strategy Tester chart, I see that the functions return constant values (-1 and/or 0) all the time, despite the existence of trades (current and closed). It looks like the EA does not see the conditions defined by these functions in its code.

In addition, so-called "executable" functions stop working, e.g., a set of functions for closing positions: ClosePosBySelect (it closes one preliminarily selected position) and
ClosePositions - Close positions at market price, etc.

Please advise what kind of glitches have appeared in the functions and what needs to be fixed, at least using one of them as an example -NumberOfPositions - Returns the number of positions?

NumberOfPositions() works fine for me! True, I keep working with MQL4 without pluses! If you're writing in an updated language, then I guess everything needs to be tailored to it or go to Freelance! Everything is commercialized with terrible force now! My heart goes out to you!

If you can somehow fitNumberOfPositions(), then ExistPositions() is not needed! You may check it this way:

if(NumberOfPositions() > 0) //вместо if(ExistPositions() == true)
----------------------------//или
if(NumberOfPositions() == 0)//вместо if(ExistPositions() == false)

Good luck!

 
borilunad:

NumberOfPositions() works fine for me! True, I keep working with MQL4 without pluses! If you're writing in an updated language, then I guess everything has to be adjusted to it or go to Freelance! Everything is being commercialised with terrible force now! !

I don't come here often, so I don't know, what does "MQL4 without pros" mean?

Do you think that those who can answer here don't do so in order to force a visitor to pay to answer an uncomplicated freelance question?

I wonder how much the local programmers-commer would cost to fix such I.Kim's function to work in the latest version of mt4 with updated MQL:

//|  Описание : Возвращает количество позиций.                                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int NumberOfPositions(string sy="", int op=-1, int mn=-1) {
  int i, k=OrdersTotal(), kp=0;
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) kp++;
          }}}}}
  return(kp);
}
Let me remind you that Comment( NumberOfPositions(NULL, -1, Magic) ); - it constantly returns -1 even if the EA has opened positions.
 
Rita:

I don't come here often, so I don't know, what does " MQL4 without pros" mean?

Do you think that those who can answer here don't do so in order to force a visitor to pay to answer an uncomplicated freelance question?

I wonder how much the local programmers-commer would cost to fix such I.Kim's function to work in the latest version of mt4 with updated MQL:

Let me remind you that Comment( NumberOfPositions(NULL, -1, Magic) ); will always return -1, even if the EA has opened positions.

NULL as a function parameter means no parameters.

That would be better)Comment( NumberOfPositions(Symbol(), -1, Magic));

 
Rita:

I don't come here often, so I don't know, what does " MQL4 without pros" mean?

Do you think that those who can answer here don't do so in order to force a visitor to pay to answer an uncomplicated freelance question?

I wonder what the cost of fixing such a feature would be to a commercial programmer:

Let me remind you that the output of Comment( NumberOfPositions(NULL, -1, Magic) ); shows that -1 is always returned, even if the EA has opened positions.

MQL4++ updated, as they call it here!

My function returns the correct number of positions! But you have an error in Comment()! I'm sure the function works!

Try it like this:

int start()// или что у Вас там, как в обновлённом MQL4


  int BuyPos = NumberOfPositions(Symbol(),OP_BUY, Magic); //это вызов этой функции, чтобы знать, сколько у Вас баев
  int SellPos = NumberOfPositions(Symbol(),OP_SELL,Magic);//а это для селлов



  Comment("Buy ",BuyPos," Sell ",SellPos);

This way you will see everything exactly on the chart, apply the BuyPos and SellPos variables to check in the conditions! See how I have it:

      if(BuyPos == 0 && SellPos == 0) 
      {
// и так далее ...

Good luck!

 

Thank you, borilunad and vadynik, for the tip!

Indeed, the function is working! Here's a humble thank you for the helpful tip:https://www.youtube.com/watch?v=SFJeHI2LVX4&feature=related!

 
borilunad:

Everything is being commercialised with terrible force now! My heart goes out to you!

Boris, aren't you ashamed to say that? Count how many pages you've written trying to help you. And this is your gratitude to all those who helped you? I don't remember them all, but Artem (artmedia70) kindly took care of your problem and got in return...
 
Rita:

Here is an alternative. The function is only called if the number of orders has changed. Additionally it can be called if the order type has changed.

// переменные глобального уровня
int Total[6];
int ot;

void OnTick()
{
 if(ot != OrdersTotal())
  CountTrades();

  Comment("Ордеров BUY ", Total[OP_BUY], "\n"
        , "Ордеров SELL ", Total[OP_SELL], "\n"
        , "Ордеров BUYLIMIT ", Total[OP_BUYLIMIT], "\n"
        , "Ордеров SELLLIMIT ", Total[OP_SELLLIMIT], "\n"
        , "Ордеров BUYSTOP ", Total[OP_BUYSTOP], "\n"
        , "Ордеров SELLSTOP ", Total[OP_SELLSTOP], "\n"
}
void CountTrades()
{/*********************Подсчёт открытых ордеров**********************/
  ArrayInitialize(Total, 0);
           int type, total = OrdersTotal(); ot = 0;
            for(int i = 0; i < total; i++)
             {
              if(OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
               {
                type = OrderType();
                 Total[type] += 1;
                ot++;
               }
             }
}/*******************************************************************/
 
Rita:

Thank you, borilunad and vadynik, for the tip!

Indeed, the function is working! Here's a humble thank you for the helpful tip:https://www.youtube.com/watch?v=SFJeHI2LVX4&feature=related!

Thank you! Only the next function suggested to you may be glitchy, since it's written in MQL4++!
Reason: