Self-learning the MQL5 language from scratch - page 51

 
SanAlex:

Doesn't anyone have a summer house? Or just go for a walk with his wife.

That's another topic of discussion.)

 
VVT:

This is a different topic of discussion )

here is a recurring topic - I want to save you from Schizophrenia

 
SanAlex:

Doesn't anyone have a summer house? Or just go for a walk with the wife.

I am on self-isolation for at least another week, so I have a lot to work on and learn. I have a lot of work to do and a lot to learn.

Sincerely, Vladimir.

 
MrBrooklin:

I still have at least a week of self-isolation, so I have a lot to work on and a lot to learn. So, no time for walks yet.

Sincerely, Vladimir.

You can talk to your family on the phone - take your mind off the computer and do something at home.

 
SanAlex:

You can talk to your family on the phone - take your mind off the computer and do something at home.

Please, if you have something to write on the subject, I will read it with great interest. I have talked to all my relatives and have been distracted from computers at home several times.

For example, if you have some free time and a desire to help me with TK for trailing stop, I will only be grateful:

the trailing algorithm on paper: i.e. make a detailed ToR, point by point, without a code of how it should work in your opinion. We will work with this in the future.



Sincerely, Vladimir.

 
MrBrooklin:

Please, if you have something to write on the subject, I will read it with great interest. I have already spoken to all my relatives and have been away from the computer a few times on domestic matters.

Regards, Vladimir.

I didn't mean to offend you - you are just killing your body in your old age.

 
SanAlex:

I meant no offence - you're just killing your body in your old age.

No hard feelings! At the moment I am more interested in constructive communication. Thank you for concern about my body!

Regards, Vladimir.

 
MrBrooklin:

Please, if you have something to write on the subject, I will read it with great interest. I have already spoken to all my relatives, and have been away from the computer several times on domestic matters.

If you have free time and wish to help with TK for trailing stop, I will only be grateful:



Sincerely, Vladimir.

I can offer you trailing stop from Horizontal Lines

very handy thing! in writing code from Vladimir Karputov

https://www.mql5.com/ru/forum/233860/page43#comment_13219147

 
SanAlex:

I can suggest trailing from Horizontal Lines

very handy thing! in writing code from Vladimir Karputov

https://www.mql5.com/ru/forum/233860/page43#comment_13219147

Interesting example to study. Thank you!

Regards, Vladimir.

 

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 for automation of work on trailing (tracking) level of Stop Loss of open position with already specified levels of Take Profit andStop Loss.
  2. In the Expert Advisor, create a block of input parameters with two parameters: set "trailing level" and set "trailing step".
  3. When new quotes come in, process them with OnTick( ) function. 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. We refresh the quotes.
  7. If there is an open position, we continue.
  8. We define the type of an open position: Buy or Sell.
  9. If there is an open Buyposition , 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 at what level it has risen.
  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. If the position isSell, we define where the current price is relative to the price of the open position .
  15. If the current price is lower than the open position price, we check at what level it has fallen.
  16. If the current price has reached the "trailing level" specified in the input parameters, we move Stop Loss to the level without the loss equal to the opening price of theSell position. Otherwise we do nothing.
  17. 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 Sell position level by the value equal to the Trailing Stop level and so on until the price reaches the Take Profit level specified for that position .
  18. If the price turns and reaches the level ofStop Loss, the position is closed .

Please review the algorithm and give me some hints on what points have been missed.

Sincerely, Vladimir.