Trailing stop loss that advances when a new swing high or low are made

Forums ProRealTime English forum ProOrder support Trailing stop loss that advances when a new swing high or low are made

Viewing 15 posts - 1 through 15 (of 20 total)
  • #104533

    Hi all,

    another post from me. Thanks for all the help thus far, really appreciate it while I’m learning. Hope to be able to give back in due course.

    I am trying to code a trailing stop loss that places stops above recent swing highs (shoreside) and swing lows (longside). I have utilised some code I found that calculates recent fractals. It works ok but there is on key missing ingredient that I am not sure how to code.

    If we are following the trend then we should only move the stop up/down when a previous swing point is closed through, at which point the trailing stop would move to the closes swing high or low.

    Right now using the below code the trailing stop will simply move to the next identified fractal regardless of whether price has moved in our direction and closed above (uptrend) or below (downtrend) the current swing high/low. I only want the trailing stop to advance when price closes through the current swing high/low in our direction.

    Does that make sense? This is what I typically do manually when trend following intraday and works a treat. Would be awesome to automate it. Here’s the trailing stop code I currently have which is adapted from a few other sources.

    Any help gratefully received
    Roj

    #154307

    Hi,

    have you been able to solve your problem? Im looking for exactly the same solution, but I am far less gifted regarding programming than you. Would be very thankful if you could show the complete code, if you have one.

    Greetings from the alps!

    #154312

    Line 32 should read:

    and line 44 should read:

     

    1 user thanked author for this post.
    #154407

    Thank you very much!!!

     

    #154445

    Can I please ask another question which I can’t find the answer to, but I think is simple.

    I have programmed a screener and manually select the instruments it suggests. Then I start the trade with a stop below the last swing extreme.

    Afterwards the program should kick in to draw the stop automatically.

    But an automatic trading system says it needs a buy and sell order. How can I make the algorithm work on an already existing trade?

    I think if I try to make an indicator and link the stop-sell (or -buy) order to it, then this will be only pssible intra-day. But my trades normally last longer.

    I’d be very thankful for a hint, how to solve this problem.

    #154449

    Perhaps it would work if the last lines are changed from:

     

    to

     

    ?

    MODERATORS EDIT: Your post has been edited. please use the ‘Insert PRT Code’ button when putting code in your posts.

    #154454

    Your solution would do a Stop & Reverse OR accumulate positions.

    Manual and Automatic trading cannot be combined.

    You can only alter trades opened automatically, though this will shut your strategy.

     

     

    1 user thanked author for this post.
    #154474

    Thanks again Roberto,

    and it wouldn’t be possible to construct an indicator based on the swing-extreme trailing stop (which would exceed my abilities) and then link this indicator to an alarm and this alarm to a sell trigger?

    #154482

    Indicators can only return numeric values.

    Alerts can only be set manually according to what indicators return.

     

    1 user thanked author for this post.
    #154535

    Thanks again, Roberto. But I don’t really understand your sentence: Indicators can only return numeric values.

    Is it not the case, that this indicator would return numeric, albeit distinct stop-loss levels?

    I’m really thankful for your time and knowledge but I would really love to solve this problem As an amateur I would think that there has to be a way to automate this, since it doesn’t seem to be to complex. Do you please have any idea if I could ask somewhere or if there any other way?

    Sorry for bothering you, best regards, Michael

     

    #154550

    I mean it cannot set nor trigger alerts.

     

    1 user thanked author for this post.
    #154553

    Try what you want to do using the Alert Function with it’s integral Trade Open function.

    Try above using a stnadard Indcator … e.g Bollinger using the Close Crosses Over BollDown on the Alert Function.

    If above does what you want then you are half way there?

    1 user thanked author for this post.
    #154622

    Hello Grahal, thank you! I think your suggestion may be the same I mentioned above (to construct an indicator based on the swing-extreme trailing stop (which would exceed my abilities) and then link this indicator to an alarm and this alarm to a sell trigger)?

    If this works, the code has to be changed from trading advice to definition of a indicator and I must say that above my abilities. Could someone of you perhaps help – if this way makes sense?

    Another different solution might be to do it completely via an automated trading approach using a simple trade entry advice after the screener suggested a good candidate at bar “[1]”, i.g. for a long trade:

     

    #154624

    ligand  – Please always use the ‘Insert PRT Code’ button when putting code in your posts. I have edited your last post.

    1 user thanked author for this post.
    #154923
    1. The code line starting with defparam gives an error , but why?

    2. Roberto, I thought you gave a hint to another error in the code from Thally besides “max(newSL,SupportPrice[1])”, but I can’t find it anymore. Did you erase this post?

    Thanks, Michael

Viewing 15 posts - 1 through 15 (of 20 total)

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