Coding an MAE/MFE

Hi i wanna try something new that i havent seen anyone else doing. I wanna calculate my latest buyprice and subtract that with the highest price my trade position have been to.

Lets say that i enter EUR/USD at 1.17785 then the price goes up to 1.17855 and then goes down to 1.12850 i want the indicator to make the calculation 1.17785-1.17855=-0,0007

This has nothing new, it’s called MAE/MFE.

If you can’t find something already existing, you can code it or ask someone to code it for you.

Wanna help me code it?

Lets say i Buy in at “buy1” The indicator will now calculate the difference between “Buy1” and “MFE”, 20% of that difference we can call X. When the price goes down from MFE, and the value of X away from MFE the indicator will Sell. The price then goes down to “Turn”, and starts to go upwards, when the price goes up the same value of X the indicator will buy in again and recalculate the new X. and keep doing the same thing again and again.

My question now is:

What is what i call “Buy1” called in MQL5 langue?
What is what i call “MFE” called in MQL5 langue?
What is what i call “Turn” called in MQL5 langue?

The programwill then be optimized with different other strategies. this is just a way i wanna try and calculate my stop losses and take profits.

Tracking a position’s MFE (Maximum Favorable Excursion) or MAE (Maximum Adverse Excursion) can be accomplished in the same way as one would implement a continuous Trailing-Stop or even for such common Indicators such as Donchian Channels or Chandelier Exits .

So, have a look at MQL’s own OOP library code or the many examples in the CodeBase. In fact, although it is not for MQL5 but can be used as a reference, there is even one MQL4 Script submission specifically for MAE/MFE calculations:

Thank you for the answer. Is what i call “turn” really MAE even tho i already sold?

Yes and no! It depends on how you are classifying your original position’s life time if it were not closed prematurely by other means except for the original conditions that defined its existence in the market. Also, in “hedging” situations, one order’s MAE can easily be another’s MFE (and vice verse). It all depends on how you are looking at it, whether it be at individual trades or a “net” position of a basket of trades.

It can get rather complicated if you don’t fully understand the concepts, so I would suggest reading up on the two terms MFE (Maximum Favorable Excursion) and/or MAE (Maximum Adverse Excursion) , either on the Internet (Google search) or in books offering more in depth explanations.