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

 
artem artem #:

MakarFX, thanks! Now there is no extra non-signal first order, but now for some reason the first signal order (normal) is entering 2 candles earlier))) I attached a screenshot of the tester to my message, but even in spite of this first order - the most important thing is done, thank you very much again) With magicians got it, then I will make an external variable and when I will attach the explorer to a particular currency pair chart, I will change the number for each pair individually.

I will look at the opening.

It is not necessary to change the magik, if the symbol is controlled.

 
Nerd Trader #:

I've already forgotten... and in the beginning I did so (it's good that I locked it), but the condition method seemed unreliable, I wanted something more obvious to indicate a changed order.

Well, you still need to check the conditions on every new tick, if it didn't work on the previous tick - it will change on the new tick.

And the error processing should be done.

 
Nerd Trader #:

I'd already forgotten... and I did so in the beginning (it's a good thing I've committed), but the way of the condition seemed unreliable, I wanted something more obvious to indicate a changed order.

//+------------------------------------------------------------------+
if(OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderTakeProfit(), 0))
   ObjectCreate(0,OrderTicket(),OBJ_ARROW_UP,0,Time[0],Bid);
//+------------------------------------------------------------------+
int NameObject()
  {
   int ticket=-1;
   for(int i=0;i<ObjectsTotal();i++)
     {
      ticket=StringToInteger(ObjectName(0,i,0));
     }
   return(ticket);
  }
//+----------------------------------------------------------------------------+
void GetTicketOrder()
  {
   int result=-1;
   for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) 
     {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) 
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            if(OrderType() == OP_BUY || OrderType() == OP_SELL)
              {
               if(OrderTicket() == NameObject())
                  {
                     делай все что хочешь
                  }
              }
           }
        }
     }
  }
 
EVGENII SHELIPOV deposit currency, the whole order grid is closed

Please help me to change the code so that there would be points instead of Profit. Thank you.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает суммарный профит открытых позиций в пунктах         |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int GetProfitOpenPosInPoint(string sy="", int op=-1, int mn=-1) {
  double p;
  int    i, k=OrdersTotal(), pr=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 (mn<0 || OrderMagicNumber()==mn) {
          p=MarketInfo(OrderSymbol(), MODE_POINT);
          if (p==0) if (StringFind(OrderSymbol(), "JPY")<0) p=0.0001; else p=0.01;
          if (OrderType()==OP_BUY) {
            pr+=(MarketInfo(OrderSymbol(), MODE_BID)-OrderOpenPrice())/p;
          }
          if (OrderType()==OP_SELL) {
            pr+=(OrderOpenPrice()-MarketInfo(OrderSymbol(), MODE_ASK))/p;
          }
        }
      }
    }
  }
  return(pr);
}
 
artem artem #:

MakarFX, thanks! Now there is no extra non-signal first order, but now for some reason the first signal order (normal) is entering 2 candles earlier))) I attached a screenshot from the tester to my message, but even in spite of this first order - the most important thing is done, thank you very much again) With magicians got it, then I will make an external variable and when I attach the espert to a particular currency pair chart, I will change the number for each pair individually.

What period was tested and what was the number of confirmations?
 
MakarFX #:

Makar as far as I understand it should be tried instead of the CalculiteProfit() function

 
EVGENII SHELIPOV #:

Makar as far as I understand it should be tried instead of the CalculiteProfit() function

yes

and change it

int op = GetProfitOpenPosInPoint("", -1, Magic ); 
 
MakarFX #:
What period did you test and what was the number of confirmations?

MakarFX, on that screenshot, which I attached, tested on EUR / USD - M 30 - all ticks - 01.08.21 to 03.09.21 - 26 orders were ( but I changed the constant from 4 to 8, I decided to look at a larger number of candles)

If we return the constant to 4 candlesticks, then for the same period - then 35 orders, but the first order also comes in 2 orders earlier

 
MakarFX #:

yes

and you change it.

Makar, can you tell me if there is only a min and max order?

 
EVGENII SHELIPOV #:

Makar, can you tell me if there is only a min and max order?

Do you mean "min and max" by ticket or price?
Reason: