MAE maximisation

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #143431 quote
    Kovit
    Participant
    Senior

    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

    #143510 quote
    Nicolas
    Keymaster
    Master

    Take the average of MAE and use it as a dynamic takeprofit.

    Kovit thanked this post
    #143640 quote
    Paul
    Participant
    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!

    Kovit thanked this post
    #143648 quote
    zilliq
    Participant
    Master

    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 😉

    Paul and Kovit thanked this post
    #143693 quote
    Nicolas
    Keymaster
    Master

    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
    Paul and Kovit thanked this post
    #143694 quote
    Nicolas
    Keymaster
    Master

    Hmmm MAE or MFE? 🙄

    Sorry, I must be tired, my above code is the average MFE!!

    Kovit and thanked this post
    #143702 quote
    Paul
    Participant
    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?

    #143727 quote
    Nicolas
    Keymaster
    Master

    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?

    #143728 quote
    Nicolas
    Keymaster
    Master

    V11 is free, open a free EOD account at prorealtime.com, you will be able to test…

    #143732 quote
    Paul
    Participant
    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!

    #148396 quote
    Kovit
    Participant
    Senior

    Thank you everyone for all the input and responses and lol I must have been tired myself as I meant mfe not mae.

    #183524 quote
    Khaled
    Participant
    Veteran

    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

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

MAE maximisation


ProOrder support

New Reply
Author
author-avatar
Kovit @kovit Participant
Summary

This topic contains 11 replies,
has 5 voices, and was last updated by Khaled
4 years, 1 month ago.

Topic Details
Forum: ProOrder support
Language: English
Started: 09/05/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...