Self-learning the MQL5 language from scratch - page 53

 
SanAlex:

Part 3.


Your slips are a mauvais ton here. Wrap everything up in an attachment
 
MrBrooklin:

Yes, Alexey, I've already seen this code. It's in the form of an include file. To be honest, I didn't find anything about the symbol in it, though I looked through it several times. Perhaps I misunderstood something or am just searching poorly.

Sincerely, Vladimir.


I will reply in the evening. I am using the library of trawls and their types provided by Yury Dzyuban without any problem in trading robots and that I am using on MT4 up to now.
The approaches there are the same as on MT5.
 
Aleksey Masterov:

Your slipshods here are a mauvais ton. Wrap it up in an attachment

I've learned a new word for myself - mauvais ton.

(Bad manners; behaviour, manners and conduct considered inappropriate, indecent, unacceptable in a given society; bad, ill-mannered)



 
SanAlex:

I have learned a new word for myself - covetousness

("bad manners"; behaviour, manners and actions considered inappropriate, indecent, unacceptable in a given society; bad, ill-mannered).




Your slip-ups are of no interest to anyone here. It's customary to post it as an attachment, if you post it this way it doesn't mean more people will bother to read it...

It interferes with reading the thread and answering the question.
 
Aleksey Masterov:

No one here is interested in your scribblings. It is customary to post it as an attachment, if you do so, it doesn't mean that more people who want to read it...

It interferes with reading the thread and answering the subject.

I won't get in the way - communicate!

------------------------------------

although you could've picked something up in those tatters...

 
Fast235:

i equals the number of open positions, so many cycles will be with printing

you need to remove the "=" sign in why you need to go through the loop when the number of open positions is 0. on this null call the second print came out

Hello! Thank you very much! Now I don't understand why I thought the cycle starts with "0" instead of "1". To make a long story short, I should stop studying at night, as I used to do in my youth.

Regards, Vladimir.

 
Aleksey Masterov:

I will reply in the evening. With the library of trawls and their types from Yu. Dzyuban, which works on combat robots without any questions and which I use at the moment on MT4.
The approaches are the same as on MT5.

Hello Aleksey! I will be very grateful for any help.

Sincerely, Vladimir.

 
MrBrooklin:

So, based on the literature I read, I wrote a short algorithm for creating an Expert Advisor with the Trailing Stop function:

  1. Let's create an Expert Advisor to automate trailing (accompanying) the Stop Loss level of an open position with already specified Take Profit andStop Loss levels . And what is the difference if the Take Profit and Stop Loss levels are already set for the position or not? If the stop level is not specified, it will be set by the Expert Advisor; if it is, it will be changed into a new level according to the algorithm. The Expert Advisor will be indifferent to the take profit level of the position.
  2. In the Expert Advisor, create a block of input parameters with two parameters: set " Trailing Stop Level" and set "Trailing Step". In fact, we are talking about two algorithms in one: the first moves stop to Breakeven, the second trails it further along the movement. In the negative zone, the stop is not trailing.
  3. When new quotes come in, we process them using OnTick( ). Trailing works only when a new tick comes for the current symbol.
  4. Let's create and run a loop to search all positions.
  5. If we suddenly find no open positions, we return to the loop
  6. Let's refresh the quotes. There is no need to update anything. The trading environment is updated automatically. We just need to request the data at the time of the OnTick event.
  7. If there is an open position, we continue. Why all these details from point 4 to point 7? Instead, we should write simple: For each Buy position we define... and then from point 9
  8. Determine the type of an open position: Buy or Sell.
  9. If the position is Buy, we define where the current price is located relatively to the open position price.
  10. If the current price is higher than the open position price, we check its level.
  11. If the current price has reached the "trailing level" defined in the input parameters, we move theStop Loss to the level without the loss that equals the opening price of theBuy position. Otherwise we do nothing.
  12. If the current price exceeds the Trailing Stop level by the value equal to the Trailing Stop level, theStop Loss is moved from the opening price level of Buy position by the value equal to the Trailing Stop level and so on until the price reaches the Take Profit level specified for this position .
  13. If the price turns and re aches the level ofStop Lossalready moved , the position is closed .
  14. [A similar description follows for a Sell position.]
  15. If the position Sell is opened, we define where the current price is relative to the price of the open position.
  16. If the current price is lower than the open position price, we check at what level it has fallen.
  17. If the current price has reached the trailing level specified in the input parameters, we move the Stop Loss to the level without losses equal to the opening price of the Sell position. Otherwise we do nothing.
  18. If the current price has exceeded the trailing level by the value equal to the "Trailing Stop Loss" level, the Stop Loss will be moved from the Sell position opening price to the value equal to the "Trailing Stop" step and so on until the price reaches the Take Profit level specified for that position.
  19. If the price turns and reaches the level of Stop Loss already moved, the position is closed.


I have made some corrections

 
Here is a simplified version of the trailing description:
  1. Trailing stops are processed when a new tick is received, in the OnTick function.
  2. A trailing stop consists of two consecutive parts:
  3. Part 1. For each open position the price is calculated, and when it is reached, its stop-loss is moved to Breakeven.
  4. Part 2. After the stop loss has been moved to breakeven, the algorithm of stop pulling following the price is activated for the active position.

I will not describe in detail the algorithms of stop transfer for parts one and two. You have already described them in general correctly. If you describe them, you should further follow the pattern:

Part 1. Breakeven:
  • For buying;
  • For Sell;
Part 2. Pulling up the stop:
  • To buy; To sell;
  • For selling;
Совершение сделок - Торговые операции - Справка по MetaTrader 5
Совершение сделок - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
 
MrBrooklin:

Hello Alexey, I would be very grateful for any help you can give me.

Regards, Vladimir.

You have two major errors in your TOR description:

1. You are going too much into low-level details. Why, for instance, write (incorrectly, by the way) "you must return to the loop if no positions are found". If there are no positions, there will be nothing to process. You don't have to return to the loop, you just have to exit and wait for a new tick, maybe something will appear there, maybe not. You don't need to describe cases of "what if not..." - There are an infinite number of such cases, you can't describe them all. Instead, focus on the "what ifs".

2. The TOR clearly shows a desire for consistency. Do not do this. Go from general to specific:"I need a stop that a) transfers to Breakeven, and b) when it is transferred to Breakeven, it is pulled up by trawl. The rules of transfer to Breakeven and pulling up the stop, attached below..." . - I assure you , any freelance programmer would understand such TOR, and for him, the programmer, such TOR will be much easier and clearer than deal with loops, which come back to themselves, if there is no position, etc.

Reason: