This is a simple implementation of the MFE/MAE Tool for TradingView. It's a quite powerful tool and pretty useful in systematic trading, but I don't see many trader using it these days. It's created for EMA cross, but you can easily change it to use your own signals.
What is MAE/MFE Tool
MAE stands for Maximum Adverse Excursion - Worst P&L during the trade
MFE stands for Maximum Favorable Excursion - Best P&L during the trade
The idea is pretty simple. We take only signals without any position management or exits and measure the best/worst P&L for the next X bars after the signal was.
The primary use case for it is to understand how good your signals are . If you'll add complicated money management tools, exits, and SL/PT to your strategy, it brings quite a lot of noise. After that, it's pretty tricky to understand if your signals bring much information about future price movements. In other words, bad money management can ruin good signals, and you might discard the entire strategy without knowing that. So this is why I think it's important to check the quality of your signals separately.
Another simple way to use it is to estimate where to put SL/PT In this example, we're computing MAE/MFE in percent. We're plotting it both on the chart and computing some statistics based on it. This is why it's pretty easy to get a quick understanding of what is your SL/PT should be.
MAE/MFE tool consists of a:
Chart - it displays a point for every signal. Long/Short trades can have different colors. On hover you'll see details for this signal.
Table with stats - we're computing basic metrics for these Signals like average/min/median/max MAE/MFE, number of trades, and how many trades hit selected SL and PT. Stats are also separated by the side so you can see performance separately for longs and shorts.
The indicator is highly customizable, you can configure:
Bars you want to use to compute MAE/MFE
Side selection
SL and R:R
Styling of the chart
Position and style of the table
Parameters for the EMA
EMA cross and its parameter were selected randomly, so don't estimate to see a great performance here.
MFE/MAE tool is a pretty powerful concept. At some point, I'll create an entire article in my blog with more examples and descriptions.
Disclaimer Please remember that past performance may not indicate future results. Due to various factors, including changing market conditions, the strategy may no longer perform as well as in historical backtesting. This post and the script don’t provide any financial advice.
Thanks a Lot for this. Is there a way where we get the MAE and MFE data for each trade in the Backtest Report like the one we get in Amibroker.
QuantNomad
⋅
@narenkandala, I'm unfamiliar with Amibroker, but it's possible to output intermediate results for every trade in theory. The issue is that there are too many trades, and displaying them all with existing Pine Script tools is pretty tricky.
FredrikEJohansson
⋅
Great prgm. Thx. Would it be possible to tweak this prgm to manually insert price and time when a trade was entered/exited to get the data out?
QuantNomad
⋅
@FredrikEJohansson, We're currently working on a more advanced script for MAE/MFE. We'll add related features to time in it.
A_Traders_Edge
⋅
Should "period to close" be on time rather than barCount(for those of us who use the lower TFs to test this on, 50 bars to a highly traded asset could be 50 min on the 1min TF but for altcoins with lesser volume where TV does not print the candle if no volume/price update has occurred, 50 bars could potentially be 4hrs....skewing the end results upon comparison?
Cervinmole
⋅
Hello and thank you very much for sharing. I will have a question: could we have results that would be distorted by the 'repainting', as for backtests that use the 'request.security' functions?
QuantNomad
⋅
@Cervinmole, If you'll implement a higher timeframe properly in the security function, it should be fine.