Questions from Beginners MQL5 MT5 MetaTrader 5 - page 615

 
Hello.
I have no tabs in the tools window of MT-5 - calendar, signals, could you tell me how to add them?
 
sergey966121:
Hello.
i have no tabs in the tools window of MT5: calendar, signals, can you tell me how to add them?

The settings on the trading server are responsible for the "Calendar" tab. If there is no tab, request its inclusion from the merchant where the trading account is opened.

If there is no "Signals" tab:

If there is no "Signals" tab in MetaTrader

Added: Is it Windows operating system?

 

Hello!

I can get the TP and SL values of a position usingPositionGet...(), but how can I set the takeprofit of the whole position?

I can't specify it. Thank you!

 
Alexander Kharlamov:

Hello!

I can get the TP and SL values of a position usingPositionGet...(), but how can I set the takeprofit of the whole position?

Thank you!

Like this, using the standard library and CTrade class:

#include <Trade\Trade.mqh>
Ctrade my_trade
...
my_trade.Buy(...
//или
my_trade.Sell(...
//или
my_trade.PositionModify(...
 
Karputov Vladimir:

There you go, using the standard library and CTrade class:

Thank you!
 
Alexander Kharlamov:
Thank you!
You're welcome. Using the standard library makes programming very easy.
 
Alexander Kharlamov:
Thank you!

Here is an example of a script (PositionModify(SL).mq5) - it first opens a position, and then changes the stop loss of this position:

//+------------------------------------------------------------------+
//|                                           PositionModify(SL).mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#include <Trade\Trade.mqh>
//--- variable
CTrade   my_trade;         // object CTrade
int      my_stop_loss=30;  // stop level
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   my_trade.Buy(0.01);
   Sleep(6000);

   double m_adjusted_point;         // point value adjusted for 3 or 5 points
//--- tuning for 3 or 5 digits
   int digits_adjust=1;
   if(Digits()==3 || Digits()==5)
      digits_adjust=10;
   m_adjusted_point=Point()*digits_adjust;

   double m_stop_loss=my_stop_loss*m_adjusted_point;

   MqlTick m_tick;
   SymbolInfoTick(Symbol(),m_tick);

   double sl=NormalizeDouble(m_tick.bid-m_stop_loss,Digits());
   my_trade.PositionModify(Symbol(),sl,0);
  }

Restriction on use: it will only work correctly on netting accounts.

Files:
 

I managed to set TP for the position, thank you.

I wonder if it is possible to use MQL5 to trace the event - TP triggered? Or is it necessary to check the position status?

 
Alexander Kharlamov:

I managed to set TP for the position, thank you.

I wonder if it is possible to use MQL5 to trace the event - TP triggered? Or is it necessary to check the position status?

Of course you do, the position will inform you about the event - it is just an entity (a record in the database + something else) on the brokerage company's server.
 

I have not dealt with it yet due to impracticality, but won't OnTrade and OnTradeTransaction events trace position closing by take?

Trade

The Tradeevent is generated when a trade operation on the trade server is completed. The Trade event is handled by OnTrade() function for the following trade operations

  • setting, modification or deletion of a pending order;
  • cancelling a pending order in case of insufficient funds or upon expiry;
  • triggering of a pending order;
  • opening, adding or closing of a position (or a part of a position);
  • modification of an open position (change in stops).

TradeTransaction

As a result of certain actions performed on a trade account its state changes. Such actions include:

  • Sending a trade request by any MQL5 application in the client terminal using OrderSend and OrderSendAsync functions and its further execution;
  • Sending a trade request via the terminal graphical interface and its further execution;
  • Triggering of pending and stop orders on the server;
  • Execution of operations on the trade server side.

As a result of these actions, trade transactions are performed for the account:

  • processing of a trade request;
  • modification of open orders;
  • Changing the order history;
  • Changing the history of deals;
  • Changing positions.

For example, when a market buy order is sent, it is processed, an appropriate buy order is created for the account, the order is executed, removed from the list of open orders, added to the order history, then the corresponding deal is added to the history and a new position is created. All these actions are trade transactions. The arrival of each such transaction in the terminal is the TradeTransaction event. This event is handled by OnTradeTransaction function.


Reason: