Discussing the article: "How to develop any type of Trailing Stop and connect it to an EA"

 

Check out the new article: How to develop any type of Trailing Stop and connect it to an EA.

In this article, we will look at classes for convenient creation of various trailings, as well as learn how to connect a trailing stop to any EA.

Continuing the topic about trailing stop started in the previous article, here we will consider trailing classes for convenient creation of various algorithms for trailing StopLoss positions. Based on the created classes, it will be possible to create any algorithm for shifting stop levels: by stop shift from the current price, by indicators, by specified StopLoss level values, etc. After reading the article, we will be able to create and connect any algorithms for shifting stop positions to any EAs. At the same time, the connection and use of trailing will be convenient and clear.

Let's briefly consider the trailing stop operation algorithm. Let's agree that three operating conditions can be used for each trailing:

  • trailing start — number of points of position profit, upon reaching which a trailing stop is triggered;
  • trailing step — number of points that the price should move towards the position profit for the next shift of the position StopLoss;
  • trailing distance — distance from the current price StopLoss is located at.

These three parameters can be applied to any trailing. Any of these parameters may be present in the trailing settings or absent if it is not needed or is replaced by some value in the trailing algorithm. An example of replacing the "trailing distance" parameter can be the indicator value the position stop loss is set at. In this case, if we use this parameter, the stop will be set not at the price indicated by the indicator, but with an indent from the indicated price by the distance value in points.

Author: Artyom Trishkin

 
Very informative article - I am reading it. I will use material from it in my robots
From the last article - thanks
These functions are intended for quick creation of moving averages in order to use their data instead of Parabolic SAR data when doing your own research to create different types of trailing - I also took note of it.
 
Roman Shiredchenko #:
When doing your own research to create different types of trailing

On fractals and Ishimoku are also good options.

 
Love it! I will use it in all my personal bots.
 

Artem, your PSAR trailing is not working properly. I can't explain it in words, take a close look at each close. It closes at the wrong time, and it doesn't close on time. Can close long on a downward PSAR, but should only close on an upward PSAR. It may skip several PSAR switches altogether, although there were closing conditions during them.

There is too much simplification in the code - it just takes the PSAR value and uses it as SL. I guess it should work for muwings.

Take a look at how I control the closing condition:

        if (tick.ask > PSAR_BufClose[0] && PSAR_BufClose[1] < PSAR_BufClose[0]) {
                buy = PSAR_CloseWeight;
                return;
        }
        if (tick.bid < PSAR_BufClose[0] && PSAR_BufClose[1] > PSAR_BufClose[0]) {
                sell = PSAR_CloseWeight;
                return;
        }
        if (tick.bid < PSAR_BufClose[0] && tick.ask > PSAR_BufClose[1] && PSAR_BufClose[1] < PSAR_BufClose[0]) {
                buy = PSAR_CloseWeight;
                return;
        }
        if (tick.bid < PSAR_BufClose[1] && tick.ask > PSAR_BufClose[0] && PSAR_BufClose[1] > PSAR_BufClose[0]) {
                sell = PSAR_CloseWeight;
                return;
        }

Here PSAR is used to give a signal instead of setting a moving SL, but the essence is the same.