Maximum Favorable Excursion calculation

I have a formula that specifies a BuyPrice at some value between the daily Low and High, backtested using daily historical data. The backtest tradelist report shows a MFE value calculated as (High - BuyPrice) / BuyPrice, but there is no way of knowing if the High occurred before or after the intraday entry. For a long position, I would like to assume the High occurred before the buy order execution. Here is an example:

Symbol = PTEN
High = 22.40
BuyPrice = 21.18718

Is there a way to ignore the High price of the entry bar when calculating MFE for a long position?

No, because it is MAXIMUM favorable excursion. Maximum means the highest possible. Ignoring High would mean that you could have actual movement higher than MFE which obviously would be wrong. Since as you noted you don't know when High was reached including it means to err on safer side. The same way MAE includes Low (worst case).

1 Like

Yes, I see your point. I'm not sure how other people use MFE; I want to use it to detect opportunities for improved exits. Maybe I can create a custom metric.

Hi Steve,

Gone through many ways to get Custom MFE and MAE which is calculated based on High and low after entering trade but wasn't successful. Did you happen to solve that mystery.

@RaMb0 I focused my efforts in other areas and did not develop a custom MFE, MAE metric. The special cases you need to consider are the entry bar and exit bar; for all the other bars you can use the high and low prices.

@Steve. Cool. Will try once again this weekend.

Buy = .....Buy Conditions;
Short = .... Sell Conditions;

SignalBar = BarsSince(IIf(Buy==1,Buy,Short));
HighestSinceEntry = HighestSince(SignalBar == 1,High);
LowestSinceEntry = LowestSince(SignalBar ==1,Low);

//=========================================Custom Back Test Columns========================================== 

StaticVarSet("HighestSinceEntry" + Name(),HighestSinceEntry);
StaticVarSet("LowestSinceEntry" + Name(),LowestSinceEntry);

SetCustomBacktestProc( "" );

if ( Status( "action" ) == actionPortfolio )
    bo = GetBacktesterObject();
    bo.Backtest( True );
    lastdt = LastValue( DateTime() );   //Reference :

    // iterate through closed trades
    for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
        // Exploration columns in BackTest result Screen
        HighestSinceEntryArray = StaticVarGet("HighestSinceEntry" + trade.Symbol);
        trade.AddCustomMetric("HighestSinceEntry",Lookup(HighestSinceEntryArray, lastdt),dec = 2);
        LowestSinceArray = StaticVarGet("LowestSince" + trade.Symbol);
        trade.AddCustomMetric("LowestSince",Lookup(LowestSinceArray, lastdt),dec = 2);

    // generate trade list
    bo.ListTrades( );

Sharing code here for those who are trying to get highest and lowest value after entering the trade. This might help in coding customized MFE and MAE.

In above code, I have just explored columns stating High and Low after Entry (irrespective of Buy or Short Entry).

Hence, For Buy Signal, High is MFE and Low is MAE and
For Short Signal, High is MAE and Low is MFE.

@Steve... Plz check the code once whenever you get time.

PS: I am just few days into coding world so above code might not look like Pro's work.

@RaMb0 To determine the high and low prices during a trade you need to know the highest high and lowest low between the entry and the exit. The exact timing of entry and exit depends on how you trade. As I mentioned previously, the entry bar and exit bar are special cases.

If you enter positions at the open of the entry bar, the high and low of the entry bar could be the highest/lowest prices during the trade.

If you enter positions after the open of the entry bar, the closing price of the entry bar could be the highest or lowest price during the trade.

If you exit positions at the close of the exit bar, the high and low of the exit bar could be the highest/lowest prices during the trade.

If you exit positions before the close of the exit bar, the opening price of the exit bar could be the highest or lowest price during the trade.

If you enter or exit at a time in-between the open and close, there is no way to know whether your trade happened before or after the high and low.

1 Like