BreakEven & Trailing Profit: complete function

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

Viewing 15 posts - 61 through 75 (of 120 total)
  • #165998

    PositionPrice should be used instead of TradePrice, but the % modification suggested by nonetheless doesn’t work actually, because you should also change the lines where TrailStart is used to compare with the current price.

    I coded it with pips in my mind, so the code would need some in-depth modifications to work with percentages.

     

    #166002

    I would have thought that

    would simply create a value for TrailStart, and then any further reference to TrailStart will relate to that value, no?

    #166008

    Line 56, for example, compares pips. It should be changed to compare percentages.

    I think it woukd be better to convert a percentage into pips, in line 14:

    this will compute a percentage of the current price, before entering a trade, and convert it into pips.

    You may also use your Equity instead of close, and change the expression:

    You can also use such expression for StepSize.

    PriceDistance should be left as is, since it has no relation with risk and percentages.

    With such minor modifications you will accommodate for percentages without modifying the logic of the code.

     

    #166017

    Sorry Roberto, I still don’t get it. 🤔

    If pc = 0.25 and positionprice = 32000, then TrailStart will be 80

    How is this different from simply entering TrailStart = 80 without the % calculation ?

    Where Line 56 refers to TrailStart it would just read 80 and work with that … wouldn’t it?

    #166023

    Your assumption is correct because you are using SP500 o Nasdaq, or any other index with a price/pip ratio of 1. Try applying that percentage to, say, Aud/Chf which is 0.7167 with a price/pip ratio of 1/10000th!

    If you want to use some code for your personal use you can do whatever you want because that suits your needs and you know what it does, but to make a code portable it must be coded so that it can be used on every  instrument.

    2 users thanked author for this post.
    #166027

    Ok, now I see what you’re getting at – and of course it makes total sense if you want to cross over into forex.

    TBH, I mostly use the original version (from page 1), still gets great results when not using cumulative orders.

    1 user thanked author for this post.
    #166092

    This is the new code with the addition of (optional) percentages as above (as suggested by nonetheless). I added a MINSTART to prevent TrailStart from dropping below ZERO when Equity (if you plan to use it) turns negative.

    Define MyEquity somewhere in your code  (even to ZERO if you don’t plan to use it):

     

    5 users thanked author for this post.
    #166094

    That’s a great addition. With forward testing it won’t matter that much whether you use % or points, but with backtesting up to 10 years ago, when index levels were a third or a quarter of what they are now, I think % is essential to get an accurate impression of past performance.

    1 user thanked author for this post.
    #181081

    This one is seriously amazing. Great work!

    My brain is getting fried. I was trying theoretically to come up with the solution before I tried to change the code, but I’m stuck.

    What I want to achieve is to add a target at let’s say 2%. The trailing starts at 0.2%. The closer it gets to the 2%, the tighter the trailing stop is. So theoretically, when you hit 2%, it’s basically a TP.

    Any ideas?

    #181123

    I decided to code a new one, instead of changing the above code (tested on DAX, Daily TF):

    2 users thanked author for this post.
    #181124

    Holy smokes! You are amazing!

    Will give it a try today. I think it will work great for some of the strategies that hold for longer and are in quite high profits. With the old one, the gap between the SL and current price was getting bigger and bigger, so it gave back quite a lot of the profit.

    Thank you!

    #181127

    Link to code above added as Log 310 here …

    Snippet Link Library

    1 user thanked author for this post.
    #181465

    robertogozzi u are an amazing coder. But for us others it would be very intresting to get an explantion in text for how ur trailingcode works.  Whats hapens when and why. What is and how to use minstart MyEquity and so on.

     

    #181474

    This is the same code as above (test code not included), with more comments:

    if you have more questions don’t hesitate to ask.

     

     

    #181477

    Thanks roberto.

    Is their a function abow that does:

    When x% profit sl jumps to x% profit.

    Exemple: When 1% profit sl jumps to 0.1% profit.

    Lets call it “breakeven jump-code” 😊

     

    Would u like to explan MyEquity and how it works and how to use it.

    Sorry for asking so much ☺

     

Viewing 15 posts - 61 through 75 (of 120 total)

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