Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1005

 

I send a request like this to place a pending one. But it does not expire at the end of the trading day. I triedORDER_TIME_SPECIFIED_DAY but it doesn't work either. What's the problem?

MqlTradeRequest  request = {0};
         request.action = TRADE_ACTION_PENDING;
         request.symbol = _Symbol;
         request.volume = Lot;
         request.price  = high(Quant_Bars); 
         request.sl     = sl;
         request.tp     = tp;
         request.type   = ORDER_TYPE_BUY_STOP; 
         request.expiration = ORDER_TIME_DAY;
         request.magic = magicN;
MqlTradeResult result = {0};

if (OrderSend (request,result))
    {
    Print ("Ордер успешно отправлен, ошибок нет =  ", GetLastError());
    } else
       {
        Print ("Не удалось отправить запрос, ошибка = ", GetLastError());
       }
 

The TrendLineVisible function - from the standard CCurve class- is this a regression line?

How can I make this line appear on the chart completely, instead of being cut off?


 

why does it say here that ... position should only be selected by the Select or SelectByIndex method,

if the SelectByTicket method works too?

 

Help me with the ArrayPrint function - I want to get the last 100 elements of an array, and the first 100 and the last 100.

               ArrayPrint(arr_P_val_X,8,NULL,Calc_XY-100,100,ARRAYPRINT_INDEX);//Ожидаю получить 100 последних элементов, выдает первые
               ArrayPrint(arr_P_val_X,ARRAYPRINT_LIMIT);//Хочу получить 100 и 100 последний - выдает весь массив - что не так?

Calc_XY - the number of elements in the array.

 

how do I get the ticket of a trade that has just been opened?
If you use CTrade class and Buy() function.

In mt4, the OrderSend() function immediately gives a ticket.



Is there a function that gives a ticket for a position by the position index?

or is it necessary to select a position (select) first?

 
multiplicator:

how do I get the ticket of a trade that has just been opened?
If you use CTrade class and Buy() function.

In mt4, the OrderSend() function immediately gives a ticket.



Is there a function that gives a ticket for a position by the position index?

or is it necessary to select a position (select) first?

In OnTradeTransaction with transaction type trans.type == TRADE_TRANSACTION_DEAL_ADD you find a ticket in trans.position structure

struct MqlTradeTransaction 
  { 
   ulong                         deal;             // Тикет сделки 
   ulong                         order;            // Тикет ордера 
   string                        symbol;           // Имя торгового инструмента 
   ENUM_TRADE_TRANSACTION_TYPE   type;             // Тип торговой транзакции 
   ENUM_ORDER_TYPE               order_type;       // Тип ордера 
   ENUM_ORDER_STATE              order_state;      // Состояние ордера 
   ENUM_DEAL_TYPE                deal_type;        // Тип сделки 
   ENUM_ORDER_TYPE_TIME          time_type;        // Тип ордера по времени действия 
   datetime                      time_expiration;  // Срок истечения ордера 
   double                        price;            // Цена  
   double                        price_trigger;    // Цена срабатывания стоп-лимитного ордера 
   double                        price_sl;         // Уровень Stop Loss 
   double                        price_tp;         // Уровень Take Profit 
   double                        volume;           // Объем в лотах 
   ulong                         position;         // Тикет позиции 
   ulong                         position_by;      // Тикет встречной позиции 
  };
 
Hi all dear forum members, moderators, admins etc.
Please explain how to calculate the total profit of open positions in MQL5. There is no problem with it in MQL4. I'm not being lazy here, but because I do not know how to do it. Using PositionGetDouble(POSITION_PROFIT), the profit is only calculated for the first open position.

But in MQL4, OrderProfit() showsprofit on all orders. Maybe, I missed something...
Sorry, I forgot to specify hedge account type
 
Ramiz Mavludov:
Sorry, I forgot to mention the account type is hedge.

You should urgently and without fail attend an illiteracy eradication course. In mql5, as well as in mql4, before you work with a position (in mql4, an order), you should select the position. Unlike mql4, in mql5 I remember three functions to select a position. The documentation has a good description of them. The way... Don't think of it as rude.

 
Ramiz Mavludov:
Sorry, forgot to specify, account type hedge

Previous Candle Breakdown 3 code, function CalculatePositions, total profit

//+------------------------------------------------------------------+
//| Calculate positions Buy and Sell                                 |
//+------------------------------------------------------------------+
void CalculatePositions(int &count_buys,int &count_sells,double &profit)
  {
   count_buys=0;
   count_sells=0;
   profit=0.0;

   for(int i=PositionsTotal()-1;i>=0;i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
           {
            profit+=m_position.Commission()+m_position.Swap()+m_position.Profit();
            if(m_position.PositionType()==POSITION_TYPE_BUY)
               count_buys++;

            if(m_position.PositionType()==POSITION_TYPE_SELL)
               count_sells++;
           }
//---
   return;
  }

After the traversal of all positions for this symbol and Magic, theprofit variable will show the total profit.

 
Vladimir Karputov:

Previous Candle Breakdown 3 code, function CalculatePositions, total profit

After the traversal of all positions for this symbol and Magic, theprofit variable will contain the total profit.

Thank you Vladimir.