Special trailing stop – hope it is possible!

Forums ProRealTime English forum ProOrder support Special trailing stop – hope it is possible!

Viewing 14 posts - 1 through 14 (of 14 total)
  • #118868

    Hello,

    I am trying to create some sort of a trailing stop in which once I set the parameters for the initial stop loss (ATR*3) and everytime the price of the asset increases the equivalent of that stop loss I would risk a percentage  of the profits (trailing the stop). Percentage that would be changing everytime the price increases ‘N’ times the initial value of the initial stop loss;

    i.e. when the price of the asset bought has increased 1 time the ATR*3 (initial amount of the stop loss) I would risk the 100% of the profit, so the stop should be trailed to a break even position. Next if the price increases 2 times the ATR*3 (initial amount of stop loss), I would risk the 80% of the profit, meaning that I should trail the stop, but just enough to lock in a 20% profit and let the market take the other 80%, and so on…

     

    So far I have the following and I am out of ideas to code it and wondering if is even possible to do it:

     

    Would appreciate any help!

     

    #118977

    Well, so far I have been trying out this code (I think I am close to do it), but still not sure why it is not working yet:

     

    Would appreciate some help!

    #118986

    Try this:

     

    #118991

    Thank you Roberto! I will try it and let you know.

    #119032

    Hi Roberto, I tried the code you suggested, with some changes for adapting it to what I need, however it stills not doing exactly wat I need. It does trail the first stop (thank you for that! I couldn’t even that work before), however the next trailings are not done.

    I need not only the stop to trail the initial ATR*3 when the profits increase, but to trail in different proportions.

    Basically, ATR*3 = 1R, so if profit>= 1R then the stop should trail to Tradeprice;  if profits >= 2R then the stop should trail to Tradeprice+2R*80%; if profits >= 3R then the stop should trail to Tradeprice+2R*75%, and so on…

    I tried for that pourpose these codes and neither of them work:

    And this one:

     

    Do you have any inputs on how could I make the code work for what I atempt to do?

     

    Thank you!

     

     

     

     

    #119034

    You don’t need all those lines!

    My example after moving to breakeven trails SL so that it increases each time leaving your profit at risk equal to your initial SL.

    So when your profit reaches your SL, it is set to breakeven, then when it increases of another SL (your profit is SL*2) your stop loss is set to SL*1 snd so on… so that your stop loss is always set to initial SL*(n-1)  where n is the number of multiple times of SL that your profit grew.

    Use GRAPH to monitor your profits and your stop loss.

    #119036

    Right. But the SL is not suposed to trail equally. It should vary according to the increase of profit. Is there a posibility to do that?

    #119048

    You can do (almost) anything, just tell us what you want to achieve.

    #119054

    Thank you Roberto.

    I will try to explain what I am aming to achieve:

    I need to trail a stop which starts (as yo know) at ATR*3. You actually posted a code that helps me trail that stop every time the price goes up the equivalent of the ATR*3. However, that is nos exactly what I need.

     

    What I need is to trail the stop based on a pre-fixed percentage of the profits, everytime the price goes up a ATR*3 of the entry (I would call the ATR*3 of the entry “R”).

    Exactly would be like this:

     

    1. Price increases 1R, then I would risk a 100% of the profits (1R). Therefore, the stop should trail to a breakeven position (“Tradeprice”).
    2. Price increases 2R, then I would risk an 80% of the profits, meaning that the stop  should trail to a price = Tradeprice + 20% of the profits (20%*2R). Locking in 20% of the profits and letting the market take the other 80%.
    3. Price increases 3R, then I would risk a 75% of the profits, meaning that the stop  should trail to a price = Tradeprice + 25% of the profits (25%*3R). Locking in 25% of the profits and letting the market take the other 75%.
    4. Price increases 4R, then I would risk a 45% of the profits, meaning that the stop  should trail to a price = Tradeprice + 55% of the profits (55%*4R). Locking in 55% of the profits and letting the market take the other 45%.
    5. Price increases 5R, then I would risk a 45% of the profits, meaning that the stop  should trail to a price = Tradeprice + 55% of the profits (55%*5R). Locking in 55% of the profits and letting the market take the other 45%.
    6. Price increases 6R, then I would risk a 40% of the profits, meaning that the stop  should trail to a price = Tradeprice + 60% of the profits (60%*6R). Locking in 60% of the profits and letting the market take the other 40%.
    7. Price increases 7R, then I would risk a 30% of the profits, meaning that the stop  should trail to a price = Tradeprice + 70% of the profits (70%*7R). Locking in 70% of the profits and letting the market take the other 30%.

    That is namely what I need.

     

    I have been trying to code it for several days, but I have been strugling to do it. Would be amazing if you could help me!

     

    Thank you.

     

    #119070

    Ok, now I understand why you need many IF’s.

    I won’t be able to take a look at it until Monday.

    #119071

    Got it. I’ll be attentive to your thoughts.

    #119227

    Hi Roberto! Were you able to have a look at it? I am still trying to figure out how… I have been working in the code all weekend and today and still nothing 🙁

    #119239

    Well. Think I did it!

     

    Just for anyone that may be looking for something like it:

     

     

    #119243

    Great achievement!

    I had no time today to take a look at it.

     

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

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