need help coding a new trailing stop loss

Forums ProRealTime English forum ProOrder support need help coding a new trailing stop loss

Viewing 15 posts - 1 through 15 (of 16 total)
  • #69632

    So using the MFE stop loss that exists in this forum:

     

     

    I want to make the trailingstop = 50 into trailingstop = 25

    IF i cross over 100 pips in profit

     

    Meaning that When im above 10 pips in profit, i start the 50 trailing stop loss.
    But if trade goes over 100 pips in profit, i want the new trailing to not be 50 pips anymore, but 25 pips.

    Did that make sense?

    Basicly the more profit i get, the tighter the stop loss should be!

     

    Edit: Thinking out loud, could it be a good idea to limit the code above to be the trailing stop ONLY when profit is > 10 but < 100. Then just copy paste the same code but then use THAT trailing stop loss when profit is > 100 but < 200?

    just as an example..

    #69635

    Thinking out loud, could it be a good idea to limit the code above to be the trailing stop ONLY when profit is > 10 but < 100. Then just copy paste the same code but then use THAT trailing stop loss when profit is > 100 but < 200?

    Yeah that sounds good, try it and let us know please?

    I also forked this code a while ago and had a different step for Longs and Shorts.
    Nicolas and others may consider this even more curve fitting! 🙂 But from my observations, shorts in up trends behaves different than shorts in down trends (and vice versa) and so to have different  parameter values for shorts and longs can be beneficial (it can also be even more curve fitting! 🙂 ).

    Anyway I’m rambling, re your question, instead of copying the whole code again (as you said) why not use something like …

     

    #69638

    Yes that is what i want @GraHal!

     

    Make it work please 🙁 (i cant just copy paste ur code into the code right? how do i define “gain” etc?

     

    haha, i will also update. I belive this will make my algos alot more profitable. (i hope)

     

    I calculated “Peak performance” on each trade (or the Max profit on trade) and im loosing SO MUCH profit hehe 🙂

    That is the life of a trend follower tho, i will never exit on peak, except if i hit target and target is peak/close to peak..) i will always go back down with price until my exit or stop / trailing stop is hit.

    And thats fine, but if i could get more profit when im very profitable that would be great i think..

    #69640

    different step for Longs and Shorts. Nicolas and others may consider this even more curve fitting!

    I used to think like this but then realised that everything that we add to a strategy is a form of curve fitting as we only have historical data to work with. The skill is to curve fit as little as possible with as few variables and conditions as possible.

    Markets do behave in a different way when going down than they do going up – especially instruments such as indices that have an overall long term up trend – so now I do not consider it wrong to have different set ups for long or short positions. In fact the difference could just be the edge that is the difference between profit and loss.

    I normally prefer to have completely separate strategies for long and short positions to simplify the analysis of the different behaviour of the up or down of the instrument I am testing on.

    I’m not a big fan or user of trailing stops but I do think that if used then they need to be based on current market volatility rather than a set quantity of pips. Longer time frames give better results as short term time frame volatility can be very difficult to determine with much accuracy due to our old enemy market noise.

    1 user thanked author for this post.
    #69641
    1. i agree that long/short are usually 2 completly seperate beings and needs to be trated as such! meaning different stops/entries/exits are needed
    2. “if used then they need to be based on current market volatility rather than a set quantity of pips” could you give a good example? And say youre running trend following. A problem that i have is that even after 1 swing up is finished, unless it completly fucks up and just dives down again, it might be a good thing to hold on through the night and let the next day drag u up another swing up. I call these my “super-trades” and they can bring in some serious bucks if i just let them run, compared to closing say with an ATR stop.

      Any thoughts on that @Vonasi? Any way to solve that problem? I agree that a fixed amounts of pips for trailing stop is not the best model there is… but without selling the super-trades i think it might be better than to sell off the super-trades?

      Did that make sense?

    #69642

    how do i define “gain”

    Gain could be abs(Tradeprice – Close)*pipsize ?
    Or you could use Positionperf but this has to expressed like 0.001 … which would be 0.1%.

     

    #69651

    could you give a good example?

    ….which is the million dollar question….. and the answer is ‘no not really’! Which is why I do not really use stops or trailing stops very much. I prefer a strategy to assess price action and decide that now is a good time to exit rather than set levels. We all use the same theory for entry so why not for exit?

    If I do consider using a stop then TRP or ATRP (True/Average True Range as Percentage of Price) are two of my preferred volatility indicators to base it on. I find median price to be better than close as a basis for these calculations as close is just a moment in time whereas median price represents average opinion for each candle.

    1 user thanked author for this post.
    #69697

    I created this today. I belive it works fine.

    Trailing stop 1 = the trailing stop that u start out with. Works when profit is between 30-70 (in example code under)

    Trailing stop 2 = the trailing stop that starts when profit is above 70 (in example code under)

    Background:

    I was in a trade yesterday that reached 135 pips profit, target was 150. After peaking around 130-135 it dropped 60 pips until my trailing stop caught it.

    If i had a much more tight stop loss i could have maybe gotten just a 20 pip stop, meaning 40 more pips of profit. My profit ended at 135-60 = 75 pips of profit. Which ofc is nice, but if u can add +40 on that, then u increase the profit by 57%!

    So the whole idea is that my trailing stop 1 works as usual, but when i get close to target i want the trailing stop loss to tighten. So i put a limit that profit must be above 30 and below 70 for trailing stop 1 to work, and above 70+ for trailing stop 2 to work.

     

    These are just examples, i suggest u optimize the values so it makes sense for your algo.

     

     

     

    4 users thanked author for this post.
    #189156

    I created this today. I belive it works fine.

    Trailing stop 1 = the trailing stop that u start out with. Works when profit is between 30-70 (in example code under)

    Trailing stop 2 = the trailing stop that starts when profit is above 70 (in example code under)

    Background:

    I was in a trade yesterday that reached 135 pips profit, target was 150. After peaking around 130-135 it dropped 60 pips until my trailing stop caught it.

    If i had a much more tight stop loss i could have maybe gotten just a 20 pip stop, meaning 40 more pips of profit. My profit ended at 135-60 = 75 pips of profit. Which ofc is nice, but if u can add +40 on that, then u increase the profit by 57%!

    So the whole idea is that my trailing stop 1 works as usual, but when i get close to target i want the trailing stop loss to tighten. So i put a limit that profit must be above 30 and below 70 for trailing stop 1 to work, and above 70+ for trailing stop 2 to work.

    These are just examples, i suggest u optimize the values so it makes sense for your algo.

    It works great in backtest. But in real time it never changes the stop loss…? Any ideas?

    #189176

    Hi Zausen

    Welcome Aboard (I hope you read below in the friendly and helpful tone it is intended).

    If you had written just the last line of your post above we would all have known what you referred to as your post immediately followed the post above (which is what you are referring to).

    I ended up starting to read all your post then realised that it was a copy quote of the post above.

    If we all copy quoted full posts then we would end up with a slow website all muddled up and a hard to understand Forum?

    That is why we only quote the minimum text that we are referring to / answering and this is generally 1 sentence only or even a few words as part of a sentence.

    All we need do is to select a few words which show what we are referring to and click on Quote.

    Thank You

     

     

    1 user thanked author for this post.
    #189781

    See the difference between backtest and real time?

    What might be the reason…?

     

    I start with “SET STOP pTRAILING 84” before the code above

    #189785

    Probably me missing something (?) but are you sure you posted the correct screenshots … they both show same values?

    #189841

    Sorry, the picture was uploaded twice.

    In one picture you can see real results above (ending 32961) und below back test results (ending 33062) – so backtest is much better…

    #189846

    100 ish out of 33,000 is within fully acceptable difference between Backtest and Live.

    Or am I missing something again? 🙂

    #189847

    But the trailling stop is supposed to be tighter so much in profit – as you can see in backtest

    It starts with 75 then (when 75p in profit)  it should be 45 and finally (when 111 in profit) 25

    // Stops und Targets

    SET STOP pTRAILING 75

    //trailing stop 1
    trailingstop1 = 45 // this is trailing stop 1
    bottomTrailingStopValue1 = 75 //How many pips in profit before it starts to trail?
    TopTrailingStopValue1 = 110 // When should the “loose” trailing stop #1 end and when should #2 start?

    //trailing stop 2
    trailingstop2 = 25 // this is trailing stop 2
    bottomTrailingStopValue2 = 111 // How many pips in profit before trailing stop #2 starts to trail? (should be same as (“TopTrailingStopValue1″+1) (or maybe it dosnt need +1? not sure tbh)
    TopTrailingStopValue2 = 200 // should be same as target i guess.

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

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