Questions from Beginners MQL5 MT5 MetaTrader 5 - page 593

 

Hello.

Can you please tell me how to calculate the number of losing positions closed in a row.

When trading binary options in MT4 at Grand K broker.

The normal function doesn't count, this one does:

int CountLoss()
  {
   int count=0;
   for(int trade=OrdersHistoryTotal()-1;trade>=0; trade--)
     {
      OrderSelect(trade,SELECT_BY_POS,MODE_HISTORY);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
         if(OrderProfit()<0) count++;
         else  break;
        }
     }
   return(count);
  }

On the commentary, it doesn't work either.

Comments are strange in history snapshot here

a

 
Alexander Antoshkin:

How do I check for a pending order?

In the open position option

we look at

if(ePositionType == POSITION_TYPE_BUY)

if(ePositionType == POSITION_TYPE_SELL)

but what about the pending

//+------------------------------------------------------------------+
// Количество открытых отложенных ордеров
int CountTrades()
{
 int count = 0;
 for(int i = OrdersTotal()-1; i>=0; i--)
 {
  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
  {
   if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
   {
    if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
    count++;
   }
  }
 }
 return(count);
}
//+------------------------------------------------------------------+
Returns number of pending orders
 
Alexander Antoshkin:

How do I check for a pending order?

In the open position option

we look at

if(ePositionType == POSITION_TYPE_BUY)

if(ePositionType == POSITION_TYPE_SELL)

and what about the pending

Positions and orders should not be confused in mql5.

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Alexey Viktorov:

In mql5 you should not confuse positions and orders.

I have found two solutions to the problem

1.

I assigned a comment to the orders in the request, oRequest.comment = "LimitSell"; oRequest.comment = "LimitBuy";

in a global

string comment ="";

I came up with this variant

if(OrderGetString(ORDER_COMMENT)=="LimitSell")

if(OrderGetString(ORDER_COMMENT)=="LimitBuy")

I don't know if this is right, but it seems to work

2. You can do it without comments
if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_LIMIT) ....

 
Alexander Antoshkin:

2. You can do without comments
if(OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_LIMIT) ....

This is exactly what I was talking about.
 
Hello, how do I put a trailing stop into an EA in mt5?
 
bv1979:
Hello, how do I put a trailing stop into an EA in mt5?
The default EA comes with ...\MQL5\Experts\Examples\MACD\MACD Sample.mq5. Look at the function implementation ****Modified.
 

can you advise me on where to find such an advisor?

Grid, open positions only one way, Martin, close the previous position by tp or sl with opening the next one (increased if closed by sl)

 
Slava_kornev55:

can you advise me on where to find such an EA?

Grid, open positions only one way, Martin, close the previous position by tp or sl with opening the next one (increased if closed by sl)

Search in the upper right corner of the site (magnifying glass) is all searchable.
 
Karputov Vladimir:
A search in the top right-hand corner of the website (magnifying glass) will find everything.
I didn't find one
Reason: