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

 
Yevhenii Levchenko:
Do I understand correctly, that in mt5, instead of closing time, POSITION_TIME_UPDATE should be watched?
No. You need a closing trade.
 
Valerius:

TakeProfit is calculated in pips and Trailing TakeProfit is calculated in the deposit currency. Trailing TakeProfit is profit in the currency of the deposit from one or more orders, and puts stops of orders in the amount specified in the settings, i.e. at a calculated distance.

For example, Trailing Take Profit in $100 is specified in the settings. Once the price reaches the 100$ profit and goes further, the program calculates the distance of 100$ and places all stoplosses of orders in the calculated spot, if it allows. As soon as the price rolls back to the stops, all orders will be closed. In principle this is the same as Trailing Stop, only it is calculated in depo currency and trails profit. I may have made a mistake somewhere, but this is the principle. I hope I have explained it.

Trailing - movement. Trailing Stop - we move the stop according to the algorithm. Trailing TakeProfit - we move the level as it is approached according to some algorithm.

 
Artyom Trishkin:
No. You need a closing trade.

Thank you!

Here's a function for martin that checks the last trade for profit. If unprofitable, it returns the volume of the trade. How correct is it to do it this way:

double lastDealVolume() {
   datetime lastDealTime = 0;
   double volume = 0;
   if(HistorySelect(TimeCurrent() - PeriodSeconds(PERIOD_D1) * 10, TimeCurrent())) {
      int historyDealsTotal = HistoryDealsTotal();
      for(int i = historyDealsTotal - 1; i >= 0; i--) {
         if(HistoryDealSelect(HistoryDealGetTicket(i))) {
            ulong dealTicket = HistoryDealGetTicket(i);
            ENUM_DEAL_TYPE dealType = (ENUM_DEAL_TYPE) HistoryDealGetInteger(dealTicket, DEAL_TYPE);
            if(HistoryDealGetString(dealTicket, DEAL_SYMBOL) == _Symbol && HistoryDealGetInteger(dealTicket, DEAL_MAGIC) == MagicNumber &&
                  (dealType == DEAL_TYPE_BUY || dealType == DEAL_TYPE_SELL) ) {
               if(HistoryDealGetInteger(dealTicket, DEAL_TIME) > lastDealTime) {
                  lastDealTime = (datetime) HistoryDealGetInteger(dealTicket, DEAL_TIME);
                  if(HistoryDealGetDouble(dealTicket, DEAL_PROFIT) < 0) {
                     volume = HistoryDealGetDouble(dealTicket, DEAL_VOLUME);
                  } else {
                     volume = 0;
                  }
               }
            }
         }
      }
   } else Print("HistorySelect() (lastOrderVolume) error! ");
   return volume;
}

If we want to know the profit of the whole position:

-> Search all trades and get the DEAL_POSITION_ID of the last trade;
-> Search and get the profit of the whole position again using DEAL_POSITION_ID?

Or there is a shorter way?

 
Yevhenii Levchenko:

Thank you!

Here's a function for martin that checks the last trade for profit. If unprofitable, it returns the volume of the trade. How correct is it to do it this way:

If we want to know the profit of the whole position:

-> Search all trades and get the DEAL_POSITION_ID of the last trade;
-> Search and get the profit of the whole position again using DEAL_POSITION_ID?

Or there is a shorter way?

Look at the problem from another angle. Why should we need to look through the history, if we can get the position ID at the moment of position closing and select orders and deals of this position knowing everything already.

 
Alexey Viktorov:

Look at the problem from another angle. Why search the history if you can get the position ID at the moment of closing the position and select orders and trades of this position already knowing everything.

The thing is, you have to check this before you open a trade :(

But if you don't have a short one, you can always go the long way :)

 
Yevhenii Levchenko:

The thing is, it has to be checked before opening a trade :(

But if there is no short one, you can always go the long way :)

It is necessary only when restarting the Expert Advisor in OnInit to look for it that way. And in the process of working of the EA, we get the necessary data at the time of closing the position. But this is up to everyone. Some people like to load the processor with unnecessary actions.........

 
Alexey Viktorov:

This should only be looked for in this way when restarting the Expert Advisor in OnInit. And in the process of work of the Expert Advisor to get the necessary data at the time of closing the position. But all this is everyone's business. Some people like to load the processor with unnecessary actions.........

I'm a little confused, but how to trace the moment of closing a position except for requesting the state of the position at every tick? It is certainly not all positions to interrogate, but all the same on each tick request.

 
Valerius:

TakeProfit is calculated in pips and Trailing TakeProfit is calculated in the deposit currency. Trailing TakeProfit is profit in the currency of the deposit from one or more orders, and puts stops of orders in the amount specified in the settings, i.e. at a calculated distance.

For example, Trailing Take Profit in $100 is specified in the settings. Once the price reaches the 100$ profit and goes further, the program calculates the distance of 100$ and places all stoplosses of orders in the calculated spot, if it allows. As soon as the price rolls back to the stops, all orders will be closed. In principle this is the same as Trailing Stop, only it is calculated in depo currency and trails profit. I may have made a mistake somewhere, but this is the principle. I hope I have explained it.

Valeriy Yastremskiy:

Trailing - movement. Trailing Stop - we move the stop according to the algorithm. Trailing TakeProfit - we move the level as it is approached according to some algorithm.

Don't kick me, but I don't get it. In settings of the MetaEditor generated Expert Advisor which includes trailing module, the trailing level is specified in points. For example, I set the "Take Profittrailing level (in points)" = 100. How will this trailing stopper work? Correct me if I am mistaken. When the current price reaches the distance of 100 pips before the specified Take Profit level, the trailing order is activated. When the price reaches and crosses the TP, the position is not closed. The trawl simply starts following the price at a distance of 100 pips. If price reverses and goes against the position, the position will be closed by TP, or by SL if the trawl moves further than TP. Right?
Общие принципы - Торговые операции - Справка по MetaTrader 5
Общие принципы - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Перед тем как приступить к изучению торговых функций платформы, необходимо создать четкое представление об основных терминах: ордер, сделка и позиция. — это распоряжение брокерской компании купить или продать финансовый инструмент. Различают два основных типа ордеров: рыночный и отложенный. Помимо них существуют специальные ордера Тейк Профит и...
 
altec3:
Don't kick me too much, but I don't get it. In settings of the Expert Advisor, which was generated in MetaEditor and which includes trailing module, the trailing level is specified in points. For example, I set the "Take Profittrailing level (in points)" = 100. How will this trailing stopper work? Correct me if I am mistaken. When the current price reaches the distance of 100 pips before the specified Take Profit level, the trailing order is activated. When the price reaches and crosses the TP, the position is not closed. The trawl simply starts following the price at a distance of 100 pips. If price reverses and goes against the position, the position will be closed by TP, or by SL if the trawl moves further than TP. Right?

Without the code, it's hard not to answer.

 
Alexey Viktorov:

This should only be looked for in this way when restarting the Expert Advisor in OnInit. And in the process of work of the Expert Advisor to get the necessary data at the time of closing the position. But all this is everyone's business. Some people like to load the processor with unnecessary actions.........

It's not checked on every tick. If there is a signal, it starts checking and opens a trade. That's all :)
Reason: