Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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(entryExecutionexitExecution1);    

        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
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jclose, Today, 09:37 PM
    0 responses
    5 views
    0 likes
    Last Post jclose
    by jclose
     
    Started by WeyldFalcon, 08-07-2020, 06:13 AM
    10 responses
    1,413 views
    0 likes
    Last Post Traderontheroad  
    Started by firefoxforum12, Today, 08:53 PM
    0 responses
    11 views
    0 likes
    Last Post firefoxforum12  
    Started by stafe, Today, 08:34 PM
    0 responses
    10 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by sastrades, 01-31-2024, 10:19 PM
    11 responses
    169 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X