MAE MFE code/indicator

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #88818 quote
    aland
    Participant
    Average

    Hi all,

    Is there a readymade code for MAE and MFE.

    I would like to be able to answer the question:

    “what is the maximum amount ever gained since this trade started” – for MFE and the opposite for MAE for both sell and buy orders

    I started writing the code for this but am hoping it already exists

    Also, it would be good to have “what is the MFE on the last X bars”

    Thanks

    P.S – I really appreciate your help and support, it is amazing!

    #88833 quote
    Vonasi
    Moderator
    Master

    This might be of use:

    MAE and MFE calculator.

    It comes up as the top item if you type MAE MFE in the search box!

    #88837 quote
    aland
    Participant
    Average

    Thanks,

    Naturally, I checked it before posting, but it is not exactly what I am looking for, the question is does a pre built indicator exist in the language, like ATR for example or HIGH, LOW etc.

    Otherwise I can code it myself, it just takes longer…

    Thanks again!

    #88844 quote
    Vonasi
    Moderator
    Master

    There is no pre-built indicator or code that provides what you want but coding it wouldn’t be very difficult and a lot of the basic calculations are in what I wrote. You just need to start recording MFE and MAE highest highs and lowest lows distance from TRADEPRICE from the moment a position is opened and then reset it when it is closed.

    aland thanked this post
    #98428 quote
    DJB1974
    Participant
    New

    What does MAE and MFE stand for please?

    i see them when i am looking at back testing history but havent been able to find out what they mean.

    thanks

    DJ

    #98449 quote
    Nicolas
    Keymaster
    Master

    The MAE term stands for “Maximum Adverse Excursion” and refers to the biggest movement against you while you are at market.

    While the MFE (Maxime Favorable Excursion) is the inverse: maximum gain achieved while you are at market.

    DJB1974 thanked this post
    #101314 quote
    tatie
    Participant
    Junior

    I have been using Probacktest to backtest my trading strategies for over two months now on a daily basis.

    I have recently noticed that the MAE figure on the detailed report does not take into account the max movement against you on the entry bar itself; but then also noticed yesterday night by reviewing a small sample of the winning trades from the detailed report’s closed positions list that the MAE is not really the max price it went against your trade at all. This makes me wonder whether the absolute performance figures and MFE have any bearing….

    Should I trust that the return figure on the overview tab information on the probacktest results is correct?

    I normally use the MAE as an indicator of the size of stop loss required for the strategy, but how accurate is it? can I trust it? please help

    #101340 quote
    GraHal
    Participant
    Master

    a small sample of the winning trades from the detailed report’s closed positions list that the MAE is not really the max price it went against your trade at all.

    I (and I’m sure others?) would love to see examples of what you found??

    I’m not doubting what you say btw.

    #129348 quote
    Paul
    Participant
    Master

    inside a strategy, it shows mae / mfe

     

    if longonmarket then
    lowestprice=min(tradeprice(1),low)
    mae=lowestprice-tradeprice(1)
    if mae>mae[1] then
    mae=mae[1]
    endif
    
    highestprice=max(tradeprice(1),high)
    mfe=highestprice-tradeprice(1)
    if mfe<mfe[1] then
    mfe=mfe[1]
    endif
    endif
    if shortonmarket then
    highestprice=max(tradeprice(1),high)
    mae=tradeprice(1)-highestprice
    if mae>mae[1] then
    mae=mae[1]
    endif
    
    lowestprice=min(tradeprice(1),low)
    mfe=tradeprice(1)-lowestprice
    if mfe<mfe[1] then
    mfe=mfe[1]
    endif
    endif
    
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    highestprice=0
    lowestprice=close
    mfe=0
    mae=0
    endif
    
    graph round(mfe) coloured(0,0,255,255) as "Maximum Favorable Excursion"
    graph round(mae) coloured(255,0,0,255) as "Maximum Adverse Excursion"
    GraHal and eckaw thanked this post
    Screenshot-2020-05-02-at-10.32.05.jpg Screenshot-2020-05-02-at-10.32.05.jpg Screenshot-2020-05-02-at-10.27.49.jpg Screenshot-2020-05-02-at-10.27.49.jpg
    #129361 quote
    GraHal
    Participant
    Master

    Above added as Log 212 here …


    @Vonasi
    MAE / MFE Indicator added also as Log 213

    Snippet Link Library

    eckaw, Paul, Vonasi and Kovit thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

MAE MFE code/indicator


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
aland @aland Participant
Summary

This topic contains 9 replies,
has 7 voices, and was last updated by GraHal
5 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/16/2019
Status: Active
Attachments: 2 files
Logo Logo
Loading...