MAE and MFE calculator.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #77327 quote
    Vonasi
    Moderator
    Master

    Although this is an indicator I am posting it in this forum as I wrote it really to assist in deciding on stop loss and take profit levels within a strategy (not that I ever use them!)

    It is based on long positions only but just reverse the results if you want MAE and MFE for short positions. The MAE and MFE is calculated from the bar open price.

    This indicator will calculate the following:

    • The all time average MAE and MFE from open price per bar.
    • The biggest all time 1 bar MAE and the biggest all time 1 bar MFE.
    • The MAE and MFE since the open n bars back.
    • The average 1 bar MAE and average 1 bar MFE since the open n bars back.

     

    With this it is easy to check recent market volatility compared to the average and also to decide on stop loss and take profit levels. You could even use the calculations within a strategy to set dynamic levels.

    Not sure if it is worthy of the indicator library but I will submit it if Nicolas thinks it is.

    Note: just in case anyone does not know – MAE = Maximum Adverse Equity and MFE = Maximum Favourable Equity. Basically how far price moves for or against your position.

    [attachment file=77328][attachment file=77329]

    n = 12
    
    if barindex <> 0 then
    mae = mae + (open - low)
    total = total + 1
    mfe = mfe + (high - open)
    biggestmae = max((open - low),biggestmae)
    biggestmfe = max((high - open),biggestmfe)
    recentmae = (open[n] - lowest[n](low))
    recentmfe = (highest[n](high) - open[n])
    
    maerec = 0
    mferec = 0
    for i = 1 to n
    maerec = maerec + (open[i] - low[i])
    mferec = mferec + (high[i] - open[i])
    next
    endif
    
    averecentmae = maerec / n
    averecentmfe = mferec / n
    avemae = mae / total
    avemfe = mfe / total
    
    return -avemae coloured(128,0,0) as "All Time Average MAE", avemfe coloured(0,128,0) as "All Time Average MFE", -biggestmae coloured(128,0,0) as "Biggest Ever 1 Bar MAE", biggestmfe coloured(0,128,0) as "Biggest Ever 1 Bar MFE", -recentmae coloured(128,0,0) as "MAE Since n Bar Open", recentmfe coloured(0,128,0) as "MFE Since n Bar Open", -averecentmae coloured(128,0,0) as "Average Recent MAE", averecentmfe coloured(0,128,0) as "Average Recent MFE"
    
    GraHal, Pepsmile, Berra and 4 others thanked this post
    Screenshot_4.png Screenshot_4.png Screenshot_5.png Screenshot_5.png MAE-and-MFE.itf
    #77481 quote
    Vonasi
    Moderator
    Master

    An interesting way to use these MAE and MFE values is with bands based on the average of them over a look back period of n.

    [attachment file=77482]

    The above is a weekly chart. The bands have been shifted so that the values for the current forming bar are those at the close of the previous bar. It can then be easily seen if price is near to the average MAE or MFE which can be areas to enter a trade or get out of a trade. I have added a multiple so that you can move the bands to for example 1.5 times MAE and MFE if you want to.

    defparam calculateonlastbars = 200
    
    n = 6
    multiple = 1.0
    
    maerec = 0
    mferec = 0
    for i = 1 to n
    maerec = maerec + (open[i] - low[i])
    mferec = mferec + (high[i] - open[i])
    next
    
    averecentmae = close - ((maerec / n) * multiple)
    averecentmfe = close + ((mferec / n) * multiple)
    
    return averecentmae[1] coloured(128,0,0) as "Average Recent MAE", averecentmfe[1] coloured(0,128,0) as "Average Recent MFE"
    

    [attachment file=”MAE and MFE bands.itf”]

    …and here is an image of a daily strategy that buys when price drops to an average of MAE (done with MTF). It seems like there is some potential there.

    [attachment file=77484]

    GraHal, Roberto S., Berra, kj1988 and Edmond thanked this post
    Screenshot_1-1.png Screenshot_1-1.png MAE-and-MFE-bands.itf Screenshot_2.png Screenshot_2.png
    #146203 quote
    Paul
    Participant
    Master

    an old topic, but I just want to say thanks for posting this.

    Edmond thanked this post
    #146204 quote
    snucke
    Participant
    Veteran

    would you mind sharing that strategy vonasi? 🙂

    #146255 quote
    Vonasi
    Moderator
    Master

    That was a very old strategy from over two and a half years go so I don’t recall exactly which one it was. Looking at the equity curve and the positioning sizing in a constantly trending up market I can only imagine that it involved some averaging down which is not something that I would recommend as a long term strategy unless you have very deep pockets.

    Despite that disappointment MAE and MFE are very important in any strategy when deciding on exit positions for either take profit or stop loss and should most certainly not be ignored.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

MAE and MFE calculator.


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Vonasi
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/01/2018
Status: Active
Attachments: 6 files
Logo Logo
Loading...