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"