how to code MFE exit

Forums ProRealTime English forum ProOrder support how to code MFE exit

Viewing 15 posts - 1 through 15 (of 19 total)
  • #156597

    I’ve been working on a long-only scalping algo and noticed that in all cases where  MFE = 0 then that trade went all the way to the stoploss.

    So I’m thinking there may be some optimal number of bars (b) after which, if the trade has never been in profit, it may be better to close – something like this:

    but how do I code the MFE part ?

    #156626

    I found this in another thread from “Paul” – might be what you are looking for? Or may give you an idea.

    1 user thanked author for this post.
    #156635

    I found this in another thread from “Paul”

    thanks for that, but it doesn’t look like what I’m after. I’m thinking something more like

    but I don’t think that’s right either … ???

    #156657

    MFE = max favourable excursion right ?

    In this case you could try that if you want to exit at 50% of the MFE :

    (not tested)

     

     

    3 users thanked author for this post.
    #156660

    Not tested

     

    3 users thanked author for this post.
    #156668

    Thanks @roger, that is a useful piece of code but obviously will only work with positions that are in profit. What I am trying to address are long positions that open but fall straight away, never go into profit so that at close the MFE = 0

    @Dow Jones, that is exactly what I was looking for, thanks very much. The code works as expected and gives a small advantage, so it seems the original idea was a good one 😁😁😁

    Must try it on other algos.

    #157469

    Hi All

     

    I added this bit of code to an otherwise working Algo last night (which has been running for some time) and it quit the system around 3 bars after the MFE failed to go positive when opening a trade. I didnt keep the error (bah, I will next time) but it was along the lines of “quit due to a negative number”.

     

     

    any ideas? thanks!

     

    #157478

    I’m not clear on what you want to achieve here. You want to exit a short position if after 24 bars the MFE is between 0 and 6 ?

    #157479

    Not exactly… the algo will have recently opened a short position and if, within 24 bars the MFE is not over 6, i want to reverse that position and go long,

     

    it worked very well in backtest, honest guv.

    #157480

    I will bet your spread that it is not allowed (or unpredictable) to have both conditions on one line. Usually, a compiler/interpreter deals with the rightmost part first, working itself towards the left. Thus make it this :

    and it will always be fine regarding this aspect.

    So notice that with all on one line, TradeIndex will be undefined (could be -1) when (Short)OnMarket is not true.

    3 users thanked author for this post.
    #157486

    Thank you so much Peter. Im still new to coding, so this info is very much appreciated 👍

    #157596

    The above is perfectly fine and the code between THEN and ENDIF will be carried out if all four conditions separated by AND are true. It is exactly the same as:

     

    #157600

    The above is perfectly fine

    Thanks for the info Vonasi. And yes, the code works perfectly in backtest. But it did give me a “negative error” in live today.

     

    anyway… based on what you just said I took a closer look at the trade and at the exit time, the MFE was Zero and the position perf negative, so maybe it didnt like this.

    so… ive added a MAX to the code which doesnt appear to impact performance and will hopefully get rid of the error.

    you guys will make a coder of me yet :0

     

     

    #157619

    different day, same error 🙁

    works perfectly in backtest, I managed to capture the message today. this code is the only addition to the one that works on live and the one that doesnt.. please help…

     

     

    #157621

    instead of a reversal, maybe try separating it into 2 instructions, first exit the short, then enter long ??

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

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