Modified Nicolas' Trailing Stop code

Forums ProRealTime English forum ProOrder support Modified Nicolas' Trailing Stop code

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • #73306

    Sometimes it may happen that your target is not reached, but price went in your favour and you want to save some of the profits earned so far, that’s why the Trailing Stop exist!

    But in automated trading (at least until MTF will be supported) and mainly on higher TFs, Nicolas’code to support a good Trailing Stop is executed only when a bar closes, leaving room for price to pullback or even reverse, despite your trailing stop may have been triggered while the bar was forming, simply because when the bar closes price has retraced to a lower point < to your trailing stop treshold and the code is fooled into believing the price never reached that treshold!

    So, while awaiting MTF to come, I replaced CLOSE with HIGH and LOW, respectively, for Long and Short trades. So the code will compare TRADEPRICE with a higher/lower price than before, the price you would use manually when in front of your charts.

    When the bar closes and the code is executed, it will set a new SL according to those new prices in relation with TRADEPRICE and set a new SL where it wouldn’t have been set before, or closing immediately ifa price has fallen below TRADEPRICE!

    Should anyone take some further risk of a higher loss and aim at closing at breakeven instead of a loss, in case price has fallen below entry point, lines 17 and 26 can be replaced by:

    and lines 38 and 47 with:

    I tested it a bit and found out that it yields slightly poorer performances, but less losing trades and less drawdown.

    In a few months this post will, hopefully, be superseded by MTF.

    6 users thanked author for this post.
    #73311

    The last lines to replace some code should be used IF price has fallen below ENTRY POINT, otherwise with the original lines the trade would be closed in profit, as from the screenshot that I attached.

    #73318

    That is a very useful improvement Roberto, thank you so much!

    I have added, as row 41, to here Snippet Link Library

    3 users thanked author for this post.
    #173093

    Hi and thanks for above trailing stop loss code.

    Is there a multi time frame trailing stop loss code snippet that you can share or direct me to please?

    Thanks

    Sachin

    #173097

    To use it in an MTF system, simply add as first line:

    then use any other TF in your system.
    Usually this snippet is appended to strategies.

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

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