Trailing stop

Viewing 8 posts - 1 through 8 (of 8 total)
  • #45758

    Hi, I have been working on a simple startegy, but I need a specific trailing stop loss. The trailing stop needs to always pick the highest lows during the past x days. Visually it would be like a stair moving higher as the price moves higher. This should also be the case when the price moves lower, then the stair moves downwards. I have read a few posts about this in the forum, but the code posted on these threads does not work. Could anybody please give me some help about this?

    Thank you in advance!

    #45778

    Hi Gard

    I understand what you are looking for but in reality placing a stop at or even just below a previous low is a very obvious place to get yourself stopped out. Markets tend to frequently pull back to these level (just at or below a previous low) to take out obvious stops and then continue onwards. You would most likely be far better off using something like the trailing stops in the below 2 threads (trust me on this);

    https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

    https://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-excursion-mfe/

    Regards,

    #45807

    Hi Juanj

    Thank you for your reply. Yes I know, but when that trailing stop is working I can further manipulate it by multiplying it with a factor of, say 0.99, which will shift the “trailing stair” downwards. By doing so, I can find the multiplying factor that I am confortble with, and at the same time have a trailing stop that behaves the way I want to. I will also have a look at the threads you have linked.

    Thank you again for your answer!

    #45811

    Hi Gard

    maybe you think of something like this?

    at market

    Dob = LOWEST [15] (LOW) [1]

    at stop

    Dob = LOWEST [15] (LOW)

     

     

     

    #45814

    Hi Eric
    Thank you for your reply. If you try to graph it, you can see that it moves just like the low of the daily movements, i.e., up and down just like any asset. What I aim to code, is a stop that only moves upwards when the asset moves up, and any corrections down, would not lower the stop. Just like an stair. This should happen when one is long that asset, and vica versa if one is short.

    #45815

    @Gard, the code Eric provided should function as you describe.

    But maybe just to flesh it out a bit;

    where x = the number of bars to look back on (gets the highest low in that period)

    where y = the number of points/pips to place the stop below that previous low

    Note the below code will only be able to close the position at the next evaluation based on your timeframe (i.e. delayed by 1 timeframe unit)

     

    #45819

    Thank you Erik for elaborating on this. I got it to work by simplifying it and splitting up the if functions. Here is the code:

    //Trailing stop

     

    #45830

    See you managed to add the parameter for short positions on your own. Glad you have what you were looking for.

    Let us know how it works for you.

Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login