This code snippet demonstrates how to calculate and utilize the Maximum Favorable Excursion (MFE) to dynamically set take profit levels in a trading strategy using the ProBuilder language. The MFE measures the maximum potential profit for a trade from the entry point to the closing point.
defparam cumulateorders=false //dummy strategy
if rsi[14] crosses over 50 then
buy at market
endif
set stop ploss 50
//increase the array index
if not longonmarket and longonmarket[1] then
index=index+1
endif
//compute the MFE
if longonmarket then
mfe = max(mfe,high-tradeprice)
$mfeArray[index] = mae
endif
//at least 10 orders to allow the average calculation
if isset($mfeArray[2]) then
sum=0
for i = 0 to index do
sum=sum+$mfeArray[i]
next
avg = sum/index
endif
graph avg
if avg>0 then
set target profit avg
else
set target pprofit 200
endif
Explanation of the Code:
This snippet is useful for traders looking to implement a dynamic take profit strategy based on historical performance of their trades, adjusting their exit points to optimize potential gains.
Check out this related content for more information:
https://www.prorealcode.com/topic/mae-maximisation/#post-143693
Visit Link