Break even coding

Forums ProRealTime English forum ProOrder support Break even coding

Viewing 15 posts - 1 through 15 (of 22 total)
  • #71638

    I want to include code that enables a trade to go to break even after n pips. I was given this code but does not seem to work on auto back test

    Thank you

    Chris

     

    #71644

    Please try to post in the correct forum to get the best chance of assistance. I have moved your request from the ProBuilder forum which is for indicators to the ProOrder forum which is for auto-trading strategies.

    Also it is preferred if you use the ‘Insert PRT Code’ button to make your posts more readable when they include code. I have tidied up your post for you 🙂

    #71646

    I’ll assume that it is not just because there is no ‘p’ in STOP!

    Try this:

    Are you testing in tick by tick mode?

    #71648

    No that was my mistake. I have used the ‘p’ in the code.

    Thank you for moving to correct forum

    #71651

    Vonasi, How would the code be written for short entries?

    Yes I am in tick by tick mode

     

    #71652

    What I am trying to achieve is:

    to have an initial stop of 200 pips, then once the trade movies in my favor by 400 pips I want to trail stop to break even. I have a limit order set at 600 pips to take profit.

    #71653

    Your code can be abridged like that

    for SHORT trades

    This code will work for DAX. S&P500 and other instruments, but not for FX pairs, since 400 will never be reached by any currency!!!! You should use 400*pipsize to make your code portable to all instruments.

     

    #71658

    This is my basic code, and now I want it to trail to break even after 40 pips in profit.

    #71660

    Test this one, I added a few lines between 2 and 4

     

    #71667

    My analysis is that if I have 20 trades reach 40 pip profit and 16 trades reach 60 pip profit you would assume that with a 40 pip trail to break even that 4 trades would be break even if I was using a 60 pip take profit limit – which is the difference of the trades that reached 40 minus 60 pip trades.

    For some reason the theory doesnt seem to apply with this or any other code I have found.

    Am I missing something?

    #71669

    Your code can be abridged like that

    for SHORT trades

    Was your intention to do away with the BreakEven condition? Used on their own these will only close the trade if profit is above 400 and then falls in the same candle all the way back to zero. If profit is a above 400 and on the next candle drops to 300 then the sell order is not placed so there is no break even stop even though the trigger level was previously reached.

     

    #71674

    Vonasi, that was a simple suggestion on existing code, I did not even think about breakeven. There was no strategy, so I could only correct what was unnecessary and the way pips should be referenced.

    I later posted the whole strategy revised with Breakeven.

    #71676

    My analysis is that if I have 20 trades reach 40 pip profit and 16 trades reach 60 pip profit you would assume that with a 40 pip trail to break even that 4 trades would be break even if I was using a 60 pip take profit limit – which is the difference of the trades that reached 40 minus 60 pip trades.

    For some reason the theory doesnt seem to apply with this or any other code I have found.

    Am I missing something?

    That code is, as requested, for trailing to Breakeven, which is done once 40 pips profit have been reached. If they go ahead and reach 60 they’ll cash 60 pips, if the go backwards they’ll exit at the entry price. If you want to trail the whole think, it’s not just a question of breakeven, it’s a question of a complete trailing stop system.

    There’s one here that has been used for some years by many users and works quite well (MTF apart which will allow to improve the system): https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/.

    and official documentation https://www.prorealcode.com/blog/learning/kinds-trailing-stop-proorder/.

    By searching you should also find a combination of the trailing stop code with breakeven code.

    #71677

    Vonasi, that was a simple suggestion on existing code, I did not even think about breakeven. There was no strategy, so I could only correct what was unnecessary and the way pips should be referenced.

    I later posted the whole strategy revised with Breakeven.

    No problem. I was just a bit concerned that someone reading it would think that that was a working break even code. 🙂

     

    #71678

    My analysis is that if I have 20 trades reach 40 pip profit and 16 trades reach 60 pip profit you would assume that with a 40 pip trail to break even that 4 trades would be break even if I was using a 60 pip take profit limit – which is the difference of the trades that reached 40 minus 60 pip trades.

    For some reason the theory doesnt seem to apply with this or any other code I have found.

    Am I missing something?

    I would suggest graphing the close minus tradeprice and the high minus tradeprice so that you can more closely inspect what is happening when a long trade is opened (and the opposite for a short) which will give you more clues as to why it is not behaving how you think it should.

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

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