Coding help needed – flexible stop loss

Forums ProRealTime English forum ProOrder support Coding help needed – flexible stop loss

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

    Good morning,

    i have a piece of code for a strategy which has a moving profit target but a fixed stop loss.

    i would like some help  please that would keep the original target in place but in addition, add a parameter that when a different $profit is hit, the stop loss is moved to ensure i lock in a profit.

    example: target profit is 20*AverageTrueRange[15](close)

    however, if the trade is in profit say £150, then move the stop loss to £100 in profit and close trade on that pull back.

    thanks in advance, hope the above makes sense

    #245406

    There you go:

     

    2 users thanked author for this post.
    #245481

    many thanks for coming back to me, as always, much appreciated.

    however, the code moves the stop loss to a 100 loss, but still a loss – i would like the stop loss moved to a target that is positive so the trade at least makes some money – so in essence once a target is hit (the code you kindly provided), i then have 2 take profit targets, the original one as set out in initial trade and one which is lower than the current profit – ie, replacement of the original stop loss.

    in my earlier example, if my running profit hits £150 then my old stop loss which is naturally negative is replaced by a number which is positive so i lock in a definite gain – like £100 in the event of a pull back. and i also have my original target still in place so i win either way.

    i dont want a trailing stop loss per se as i am happy with 2 distinct take profit targets

    hope thats clear

    thanks in advance for your help

     

    #245499

    My fault, here’s the correct one:

    1 user thanked author for this post.
    #245556

    many thanks Roberto that is amazing – really appreciate your help – that works perfectly.

    However, the structure of the second take profit/movable stop loss has given me an idea.

    can a second one be added so it looks something like:

    if temp profit goes to 100, move stop loss/new take profit to +50

    if temp profit goes to 150, move stop loss/new take profit to +100

    make sense? the numbers dont really matter at this stage i am just trying to limit losses and maximise the gain but allow flexibility for some volatility

    thank you so much in advance

    #245562

    This version support 2 profitable SLs, the first one is triggered at a $100 gain and sets a SL to +$50, the second one is triggered at a $150 gain and sets a SL to +$100.

    When a major Gain  occurs and the first profitable trigger is the SECOND trigger, obviously there will not be a FIRST (worse) SL1.

     

    1 user thanked author for this post.
    #245596

    thank you once again Roberto for the code – works perfectly well

    much appreciated as always for your excellent help

    1 user thanked author for this post.
    #245612

    Sorry for the incorrect comment in line 1, I should have written SL 1.

     

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