• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to manually calculate the MAE and MFE values?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to manually calculate the MAE and MFE values?

    How can these values of an individual trade be accessed? I've experienced some success with the following code, though it is in de minority of the cases (5-10%) way off, compared with the StrategyAnalyzer output:

    Code:
    foreach (Trade t in Performance.AllTrades)
    {
        if (t.Entry.MarketPosition == MarketPosition.Long)
        {
            bestPriceReached = MAX(High, ((t.ExitExecution.BarIndex + 1) -  t.EntryExecution.BarIndex))[(Count - 1) - (t.ExitExecution.BarIndex -  1)];
            worstPriceReached = MIN(Low, ((t.ExitExecution.BarIndex + 1) -  t.EntryExecution.BarIndex))[(Count - 1) - (t.ExitExecution.BarIndex -  1)];
        }
        else if (t.Entry.MarketPosition == MarketPosition.Short)
        {
            bestPriceReached = MIN(Low, ((t.ExitExecution.BarIndex + 1) -  t.EntryExecution.BarIndex))[(Count - 1) - (t.ExitExecution.BarIndex -  1)];
            worstPriceReached = MAX(High, ((t.ExitExecution.BarIndex + 1) -  t.EntryExecution.BarIndex))[(Count - 1) - (t.ExitExecution.BarIndex -  1)]; ;
        }
        maeTrade = Math.Abs(worstPriceReached - t.Entry.Price);
        mfeTrade = Math.Abs(bestPriceReached - t.Entry.Price);
        etdTrade = Math.Abs(mfeTrade - t.ProfitCurrency);
    }
    These values especially seem off when the trade has only a duration of a few bars. Trying to correct for such trades using various 'if' statements hasn't helped. Could someone give me an suggestion as how to calculate the MAE and MFE of an individual trade?

    Regards,
    Last edited by J_o_s; 02-16-2011, 07:52 AM. Reason: Problem solved

    #2
    Hello,

    Thanks for your forum post.

    Looks pretty good for the mot part. If it was me trying to figure this out I would need to take one trade and focus on the math and values of this one trade.

    So if you would please, Add in Print() statements and Print out every variable such as the low found, the high found etc etc and calculated the MFE MAE manually/ see where the values are off.

    We need to identify the variable that is off here to find out what needs to be fixed first and foremost.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Brett View Post
      Hello,

      Thanks for your forum post.

      Looks pretty good for the mot part. If it was me trying to figure this out I would need to take one trade and focus on the math and values of this one trade.

      So if you would please, Add in Print() statements and Print out every variable such as the low found, the high found etc etc and calculated the MFE MAE manually/ see where the values are off.

      We need to identify the variable that is off here to find out what needs to be fixed first and foremost.

      Let me know if I can be of further assistance.
      Thanks for your reply Bret.

      After some trail and error with Print() I've uncovered the error. Because NinjaTrader exits on the open of the ExitBar, the high and low of the ExitBar shouldn't be included in the manual calculation of the MAE and MFE values. Well, obvious in hindsight, but I didn't correct for it. That was also why some values were off, and the rest of the values where just fine. Luckily, the great guys of BMT forum pointed me in the right direction, and with some "debugging" with Print() did I discover the error.

      I've attached the commented code in case someone else could use it,

      Regards,
      Attached Files

      Comment


        #4
        Hello,

        Excellent! Thanks for posting and sharing!
        BrettNinjaTrader Product Management

        Comment


          #5
          Thanks very much!!!!
          Only one remind:
          foreach()
          {}
          must be in protected override void OnTermination()

          Comment


            #6
            Hello all,

            I have tested this script (calculateMAEandMFE.cs) and found it to be giving the incorrect values (at least when compared to Performance.AllTrades.TradesPerformance.Currency.A vgMae).

            What is missing is the point size multiplication when calculating the mae and mfe.

            Also, this script does not take into consideration intrabar buys and sells. This means it is possible to include low and high values that were hit just before or just after the trade took place.

            I have created and attached a sample strategy that addresses these issues.
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by PeterGolz, 01-17-2020, 10:42 AM
            11 responses
            72 views
            0 likes
            Last Post reubenlasky  
            Started by utilizator, Today, 11:36 AM
            0 responses
            4 views
            0 likes
            Last Post utilizator  
            Started by EnveousColnago, Today, 07:24 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by tornadoatc, Today, 10:31 AM
            0 responses
            3 views
            0 likes
            Last Post tornadoatc  
            Started by EnveousColnago, Yesterday, 05:43 PM
            5 responses
            30 views
            0 likes
            Last Post EnveousColnago  
            Working...
            X