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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    79 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X