BreakEven & Trailing Profit: complete function

Forums ProRealTime English forum ProOrder support BreakEven & Trailing Profit: complete function

Viewing 15 posts - 76 through 90 (of 120 total)
  • #181482

    It’s lines 45 and 50.
    There’s no MyEquity.

    #184646

    Thank you robertogozzi for this excellent code! I’ve adopt it as my new standard.

    Through various backtests, I observed that with a single set of parameters, you can leave sizeable chunk of money on the table for (P10 trades) high stake trades. So, I thought of making staged parameters, i.e. parameters change after a certain level of profit to take the maximum juice. Please don’t pay attention to the performance of the System itself, it was just quick and dirty one for the test.

    To test the concept, I run the simulation on 10k (1) with the original code (right hand side picture), and (2) with my suggested code below (left hand side) . We can see with the original code the sum of the difference between MFE and actual performance is 432, i.e. loss of opportunity to make another 432. On the left hand side, the same difference makes only 236. So with is a tighter trailing system after a certain threshold of gain, we generate +196 of additional profit (45% of the 432!), but gained less on certain trades, but overall we are +100 over the base case. Another side benefit is the drawdown which went from -383 to -224. This is I think a proof of concept, but optimisation needs to take place on a much larger units >100k.

    Now, my coding skills are far from being perfect, so anyone who can please review the change and suggest improvements. Obviously, we can continue the serie and create Threshold1, Threshold2, etc. to reduce the difference between MFE and actual performance as the profits grow.

     

    #184779

    Good job Khaled, it actually can be improved like any other code.

    I improved mine this way:

    • when the strategy takes too long to reach the target, it might mean it could  soon retrace, so I added code to multiply the percentage (or the number of pips) saved by a factor of 1.2 (or 1,5,  or so) every, say, 100 or 200 candles; doing so will ensure that a retracement will still end in a higher profit;
    • when the profit reaches 75% target, I use another multiplier to lock in more profits.

    You can think of any kind of improvement. This may imply having a trailing stop management longer more than the strategy itself, but this is not an issue in most cases.

     

    1 user thanked author for this post.
    #186149

    I had a short position where the trailing stop never got moved yesterday and I can’t find why.

    It opened at 14711.4 (close before it opened was at 14712.8), lowest close was at 14620.2 and TS was set at 0.4%.
    TrailStartShort: 14712.8*0.4/100 = 58.9
    14711.4-58.9 = 14652.5

    It should have kicked in ~30p before the lowest close. What am I missing here?

    #186177

    Please post the code, otherwise it’s impossible to tell.

    What istrument and TF were you trading?

     

    1 user thanked author for this post.
    #186195

    Instrument: Nasdaq
    TF: 3min
    TZ: UTC-5

    The below code will replicate it. The trade opened 20:54 US/Eastern on January 20.

    But as I state in the code below, if I put “date = 20220121”, it opens the trade on 19th instead for some reason.

    #186208

    Isn’t it line 87 above that is the culprit?

    The + should be a – ?

    With original +, it sets ExitPrice way past the current price.

    #186216

    Change line 23 as:

    #186217

    You can also append these lines:

    to plot the trailing stop on your chart while backtesting.

    #186234

    Alright, I think I got it sorted now.

    I basically wanted a quick trailing stop (almost a TP), sort of. But if you add a PerCentInc on top of a high BasePerCent, you go past the current price when it’s triggered and price have to chase the stop instead of it trailing you or going straight to an exit. That was my problem.

    I also think I have misunderstood how it works, it’s quite clear now when you add the lines and tested different values.

    TrailStartShort: 14712.8*0.4/100 = 58.9
    14711.4-58.9 = 14652.5

    I thought it would keep 50% (BasePerCent) of the 58.9, so once it hits 14652.5 it sets the first SL at 14682.0. After that you factor in StepPerCent and PercentInc. But both values are used when it initially sets the SL.

    For example with the example above (0.5 and 0.5). If you use “2” for StepPerCent, it sets it way past the price (see pic). 100 sets it pretty close to the +50%.

    Not sure if I’m any wiser, but I now I know what the problem was 😉

    1 user thanked author for this post.
    #188109

    Thanks alot robertogozzi for ur great code.

    Would it be posssible to make a version of it without trailing stoploss

    Only use the Limit-line (takeprofit) I like how its dynamic .

    #188110

    Modify ur code to only get the line dynamic

    #188188

    It’s a trailing stop code snippet, what do you mean by Would it be posssible to make a version of it without trailing stoploss Only use the Limit-line (takeprofit)?

     

    #188191

    The line I marked in post #188110 is takeorofit-line and dynamic?

    Would it possible to make thos snippet without The stoploss-line?

    #188196

    The line I marked in post #188110 is takeorofit-line and dynamic?

    My guess is that you ran in to the same problem I did. If you have too high start, base and increase (in some combination), it becomes a trailing take profit after an increase.

Viewing 15 posts - 76 through 90 (of 120 total)

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