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

 
Azerus:

Kim's latest published function GetPotentialLossInCurrency (https://forum.mql4.com/ru/11287/page107) only takes into account open orders:

I tried to widen it a bit by including pending orders in it (by simply adding other types): but pending orders are not taken into account. Are they counted differently? The documentation doesn't say anything about this....


Pending orders have no "total potential loss of open positions in the deposit currency".

The GetPotentialLossInCurrency() function returns the total potential loss of open positions in the deposit currency.

It refers to positions in the market. Press F1 on these market functions, re-read the information carefully:

tv=MarketInfo(OrderSymbol(), MODE_TICKVALUE);
              if (OrderType()==OP_BUY) {
                pl+=(OrderOpenPrice()-OrderStopLoss())/po*OrderLots()*tv;
              }
              if (OrderType()==OP_SELL) {
                pl+=(OrderStopLoss()-OrderOpenPrice())/po*OrderLots()*tv;
              }
              pl+=OrderCommission()+OrderSwap();
 
Roman.:


Pending orders do not have "total potential loss of open positions in the currency of deposit".

The GetPotentialLossInCurrency() function returns the total potential loss of open positions in the deposit currency.

We are talking about positions in the market. Press F1 on these market functions, re-read the information carefully:

 

Question to programmers:
on a new bar, the Expert Advisor checks if the order on euro is alive (for example), if not - it makes a new deal, if yes - it leaves everything as it is.
put such a condition:

 for(int i=1; i<=OrdersTotal(); i++)          // Цикл перебора ордер
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:
         int Tip=OrderType();                   // Тип ордера
         if(OrderSymbol()!="EURUSD"||Tip>1){continue;}else{// Не наш ордер

      
   RefreshRates();
  double point5 =MarketInfo("EURUSD", MODE_POINT);//Запрос Point
 double bid5 =MarketInfo("EURUSD", MODE_BID); // Запрос значения Bid
 double ask5 =MarketInfo("EURUSD", MODE_ASK); // Запрос значения Ask
  double SL5 = NormalizeDouble(bid5+(Stop*point5), MarketInfo("EURUSD", MODE_DIGITS));
 double TP5 = NormalizeDouble(bid5-(Profit*point5), MarketInfo("EURUSD", MODE_DIGITS)); 
  double SL5v = NormalizeDouble(bid5-(Stop*point5), MarketInfo("EURUSD", MODE_DIGITS));
 double TP5v = NormalizeDouble(bid5+(Profit*point5), MarketInfo("EURUSD", MODE_DIGITS));  
 if ((iVolume("EURUSD",Period(),4)) > (iVolume("EURUSD",Period(),1))) { 
 ticket=OrderSend("EURUSD",OP_SELL,lot_EUR,bid5,Slip,0,0);// Открытие Sell
 OrderSelect(ticket,SELECT_BY_TICKET);
 OrderModify(OrderTicket(),OrderOpenPrice(),SL5,TP5 ,0,CLR_NONE); 
 {Alert (GetLastError());} // Сообщение об ошибке
}else{ticket=OrderSend("EURUSD",OP_BUY,lot_EUR,ask5,Slip,0,0); // Открытие BUY
 OrderSelect(ticket,SELECT_BY_TICKET);
 OrderModify(OrderTicket(),OrderOpenPrice(),SL5v,TP5v ,0,CLR_NONE); 
 { Alert (GetLastError());} // Сообщение об ошибке
}}

        }                                       // Конец анализа орд.
     }                                          // Конец перебора орд.

But the code does not work. Where is the error?

 
Cruc:

Here is a question for the programmers:
on a new bar, the EA checks if the EUR order is alive (for example, if it is not, it opens a new deal, if it is, it leaves everything as it is.
I have set such a condition:

But the code doesn't work. Where is the error?

Look what happens if there are a dozen orders and yours is the seventh (for example)

Check the first one - it is not ours.

Check the second one, it's not ours.

...

check the seventh - ours

check the eighth, it is not ours.

...

 


The idea is that when you open a bunch of orders on one pair, you can close all overlapping orders in one move.

Modify/delete order--->type---->Close overlapped orders

It deletes overlapped orders... Is there such a function in MQL?

Oops, found it:https://forum.mql4.com/ru/4822

 
ilunga:

see what happens if there are a dozen orders and yours is the seventh (for example)

check the first one - it is not ours.

Check the second one, it is not ours.

...

check the seventh - ours

check the eighth, it is not ours, set the order

...


There is only one order open on this pair. I only check for the given EURUSD symbol, but I must not have set the condition correctly

if(OrderSymbol()!="EURUSD"||Tip>1){continue;}else{

we need if(OrderSymbol()= Symbol("EURUSD"){

 
Cruc:


There is only one order open for this pair. I am checking only for the given EURUSD symbol, but I must have set the condition wrong

if(OrderSymbol()!="EURUSD"||Tip>1){continue;}else{

need if(OrderSymbol()= Symbol("EURUSD"){

If you have only 1 symbol in an Expert Advisor, you can just remember its ticket and check it every time, without going through all orders
 
ilunga:
if you have just 1 in your EA, you can just remember its ticket and check every time it is closed or not, without going through all the orders

Thank you very much for the recommendation, I almost figured it out, just do not remember if order is triggered, then ticket takes value -10?
 
Roman.:


Pending orders do not have "total potential loss of open positions in the currency of deposit".

The GetPotentialLossInCurrency() function returns the total potential loss of open positions in the deposit currency.

It refers to positions in the market. Press F1 on these market functions, re-read the information carefully:


I understand very well that the GetPotentialLossInCurrency() function is talking about open positions. I have a question: why can't pending orders be accounted for as well?

The documentation:

double OrderOpenPrice(  )

 Возвращает цену открытия для выбранного ордера.
 Ордер должен быть предварительно выбран с помощью функции OrderSelect().

double OrderStopLoss(   )

 Возвращает значение цены закрытия позиции при достижении уровня убыточности (stop loss) для текущего выбранного ордера.
 Ордер должен быть предварительно выбран с помощью функции OrderSelect().

Nowhere does it say that OrderOpenPrice and/or OrderStopLoss only apply to open orders.

 
Cruc:

Thank you very much for the recommendation, I almost figured it out, just can't remember if the order is triggered, does the ticket take a value of -10?
The ticket stays as it was