Hi guys,
I’ve been immersed in my bots for the past few weeks so apologies if the answer is already covered in the forum, I’m going to catchup on the threads this evening.
I have fine tuned an autotrading bot for good profit but I’m looking for a way to maximise the missed out MAE when I have a set take profit figure considering the trailing stop loss doesn’t kick in with my broker IG only the set stop loss.
All suggestions welcome and very much appreciated.
Thanks in advance,
Kovit
Take the average of MAE and use it as a dynamic takeprofit.
PaulParticipant
Master
That sounds easy, but I struggled & failed to code it. Could you show us how it’s done properly to calculate an average of the maximum favorable excursion from all trades done? I question if it should be separated for long & short. It could be a very usefull snippet!
You just need to use SET STOP $LOSS var with the variable var , it’s simplier
It will be the same think as finding the best MAE
For example the cut in this backtest is at 2500 USD
But remember, it’s one more variable = more overfitting 😉
The 2D chart is indeed a good way to find the average of the MFE, good spot.
I was thinking of a more dynamic way by calculating the average of MFE inside the strategy. Easier with array:
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
Hmmm MAE or MFE? 🙄
Sorry, I must be tired, my above code is the average MFE!!
Kovit and thanked this post
PaulParticipant
Master
Thanks Nicolas,
unfortunately I don’t have acces to v11 to test and I ‘am not familiar with variables.
For my purpose I was looking at MFE. Having one example helps to create the other though.
Your code covers a few problems I had, such as having a minimum number of trades before calculation can happen. However I don’t understand where the minimum of 10 orders is specified.
It mentions mae (row19), is that correct because everything else is based on mfe?
yes sorry, I changed “isset($mfeArray[10])” with only 2 orders.
BTW, as i said, it is a rough idea, while it computes correctly the average, if we have a takeprofit defined in the strategy, therefore the MFE is already known: it is the takeprofit value! Do you see what I mean?
V11 is free, open a free EOD account at prorealtime.com, you will be able to test…
PaulParticipant
Master
Yes I understand, takeprofit is a static value. Will give it thought how to put it to good use. Thanks for the v11 EOD account tip!
Thank you everyone for all the input and responses and lol I must have been tired myself as I meant mfe not mae.
Bonsoir Nicolas, merci pour ce code que je vais tester. Je ne m’y connais pas en Arrays. Est-ce que le code Long/short suivant est correct?
defparam cumulateorders=false
//dummy strategy
if rsi[14] crosses over 50 then
buy at market
endif
if rsi[14] crosses under 50 then
sellshort at market
endif
set stop ploss 50
//increase the array index
if not longonmarket and longonmarket[1] then
index=index+1
endif
if not shortonmarket and shortonmarket[1] then
index=index+1
endif
//compute the MFE
if longonmarket then
mfe = max(mfe,high-tradeprice)
$mfeArray[index] = mfe
endif
if shortonmarket then
mfe = max(mfe,tradeprice-low)
$mfeArray[index] = mfe
endif
//at least 2 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
Merci encore