Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mfe not calculated in Trade object

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

    Mfe not calculated in Trade object

    Hello, could you please have a look why MFE is not calculated properly, did I missed some required property for Trade object?

    Here is code example and screenshot attached:

    PHP Code:
    
    protected override void OnBarUpdate()
    {
        if(CurrentBar < 10)
            return;
    
        var entryExecution = new Execution()
        {
            Instrument = Instrument,
            Price = Close[9],
            Time = Time[9],
            Quantity = 1,
            MarketPosition = MarketPosition.Long
        };
    
        var exitExecution = new Execution()
        {
            Instrument = Instrument,
            Price = Close[0],
            Time = Time[0],
            Quantity = 1,
            MarketPosition = MarketPosition.Short
        };
    
        Trade trade = new Trade(entryExecution, exitExecution, 1);    
    
        Print("-------");
        Print("Entry.Price:" + trade.Entry.Price);
        Print("Exit.Price:" + trade.Exit.Price);
        Print("ProfitCurrency:" + trade.ProfitCurrency.ToString("C"));
        Print("MfeCurrency:" + trade.MfeCurrency.ToString("C")); // THIS VALUE IS WRONG!
    
    } 
    


    And additionally I want to ask if my manual calculation of MFE for LONG is correct (same is NT uses):

    PHP Code:
     var pointValue = Instrument.MasterInstrument.PointValue;
     var mfeCurrency = Math.Abs(trade.Entry.Price - MAX(High,10)[0]) * trade.Quantity * pointValue; 
    
    Attached Files
    Last edited by login_dejavu; 01-09-2020, 08:18 AM.

    #2
    Hello login_dejavu,

    Thank you for your reply.

    Here is essentially how NinjaTrader calculates MAE and MFE:

    mae = Math.Abs(worstLongPrice-myTrade.Entry.Price) * Instrument.MasterInstrument.PointValue * myTrade.Quantity;
    mfe = Math.Abs(bestLongPrice-myTrade.Entry.Price) * Instrument.MasterInstrument.PointValue * myTrade.Quantity;

    I'm attaching an example strategy that will take a trade normally and then calculate and print that trade's MAE and MFE along with the NinjaTrader calculated MAE and MFE and other information about the trade in the Output window. You can see more about monitoring for that high and low price during the trade if you open the attached code in the NinjaScript editor.

    It looks like the inaccurate values you're are from trying to manually create executions and create a trade rather than just calculating the values for a trade actually taken by the strategy. It wouldn't be supported to create a trade in this way from a strategy and expect that your values would be calculated correctly - during a trade it keeps track of the high and low from the entry to calculate the MFE/MAE and it wouldn't be able to do that.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    56 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X