Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MAE, MFE for an open trade

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

    MAE, MFE for an open trade

    Hello,

    How do I get the highest/lowest price of an instrument for an open trade (filled order)?
    Here's an example:
    5 minute chart
    - New bar opens at 22 goes to 31, drops to trigger price at 20.
    - Long order filled at time 2m:45s during a bar at a price of 20. A breakeven trigger price is set in my strategy for 30. That is, if the price hits >= 30, move the stop loss to 21 (breakeven + 1 tick)

    How do I track the highest price after order entry? Since the High of the bar is greater than 30, High[0] will not work. Tracking Close[0] may not work since price moves quickly, my code may look at Close[0] when its 29, do other stuff (Close[0] hits 30), and then look at Close[0] again but its back to 29. My strategy missed when price hits 30.

    My strategy works on Calculate = Calculate.OnPriceChange, which where I would prefer to keep for performance reasons.

    I know the Trade class has MAE and MFE, which is what I want, but that doesn't become available until the trade is completed. Is there any NT8 class that tracks MAE/MFE during an open trade?

    Thanks,
    Matt

    #2
    Hello StealthM93,

    High[0] will represent the highest price observed in that bar, since you are using OnPriceChange that value will update as new high prices are observed. Close[0] represents the current price which may not be the high but it is what set the bars high when it did reach that point in the past.

    For multi bars after the entry one way to do that would be to save the CurrentBar to a variable when you enter and then later subtract that value from currentBar which will give you a number of bars ago since the entry. That bars ago can be used as the period for MAX


    Code:
    int period = CurrentBar - storedCurrentBarVariable;
    double value = MAX(High, period)[0];

    Comment


      #3
      Thanks NinjaTrader_Jesse,

      The problem with using High[0] on the current bar is that it might be higher than the breakeven trigger that I have in place.

      Click image for larger version

Name:	image.png
Views:	134
Size:	48.7 KB
ID:	1311980
      Here's a the building of a 5-minute bar broken down in 1-minute bars (for example).

      As you can see the High[0] will be the "5-Minute bar High" which is above my breakeven trigger. So, at the point of trade entry, if I start looking at the High[0] of the bar, it'll will immediately trigger my breakeven and get me out of the trade as price trades around the entry price. I've seen this happen every so often.

      So, my question is, is there a value on a class what will provide the Trade High as represented by the green arrow.

      Comparing the breakeven trigger to Close[0] should work most of the time, but there could be an instance when Close[0] hits the breakeven trigger price put my polling of Close[0] might not catch it. So, to have a class attribute track the MAE,MFE of an open trade in real-time would be very helpful.

      Thanks,
      Matt

      Comment


        #4
        Hello StealthM93,

        If you are referencing 5 minute bar data the values you get will only be for each 5 minute segment of time. The only way to get more granular prices would be to use a more granular series. There are no special properties in regard to prices, you have the OHLCV values for each bar. To track values like you want you would have to do the math on your own using the series which matches how you wanted it to process, for example doing the math on the 1 minute series so it can be checked more frequently.

        Comment


          #5
          Thanks, NinjaTrader_Jesse.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          34 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          124 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          64 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X