Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Max Intraday Margin Used Calculation

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

    Max Intraday Margin Used Calculation

    NinjaTrader Pros,

    As part of back testing a strategy I would like to calculate the maximum intraday margin used.

    1. Is this currently available and if so, where would I go to see this metric?
    2. If not, is there any example code or a similar performance metric I could leverage as an example to calculate this value?

    Thanks for your help.

    #2
    Hello jakaniss, thanks for your post.

    Portfolio-based backtesting is currently not supported within the strategy analyzer. The intraday margin and account value will need to be represented by a parameter of your script. So you would set up two input parameters to represent the account value and the intraday margin per contract for the instrument you are backtesting. Then the strategy can calculate how much intraday margin was used throughout the backtest. Unfortunately, I do not have a specific example that demonstrates the practice.

    Please let me know if I can assist any further.

    Comment


      #3
      Chris,

      I apologize, I am still very green to the coding syntax so you lost me.

      So using the MES; What I am trying to capture is:

      Variables:
      MarginPerContract = 50

      Max ( ( Position Size * MarginPerContract ) + (Position Average Price - Current market price) * 4 ticks per point * TickSize * Position Size) )


      Scenario 1:
      The Strategy enters a 1 contract long position at 3100 and the price moves to 3095 then the intra-day margin is:

      1 Contract * $50 Margin per Contract + ((3100 - 3095) * 4 * 1.25) * 1 Contract = 50 + 25 = $75

      Say the position is closed at 3101 the Maximum Margin used for that trade would be $75

      Scenario 2:
      The Strategy enters a 1 contract long position at 3100 and the price moves to 3095 and a second long trade is placed and the market continues to move down to 3090.

      2 Contract * $50 Margin per Contract + (3097.5 - 3090) * 4 * 1.25 * 2 = 100 + (7.5) * 4 * 1.25 * 2 = $175

      If the market moves back to 3100 the maximum intra-day margin for that trade would have been $175.


      For Short Positions the math would be the same but the Average Price and Market Price would be swapped

      Max ( ( Position Size * MarginPerContract ) + (Current market price - Position Average Price) * 4 ticks per point * TickSize * Position Size) )


      I realize I am asking a lot so if there are some other example metrics likes Max Drawdown or something else that you think I could modify to accomplish this please let me know.

      Thanks again for all your time and help,

      Jason

      Comment


        #4
        Hello jakaniss, thanks for your reply.

        I do not have an example that demonstrates the idea, unfortunately. We can make samples to help when applicable, but when it involves custom calculations and developing entirely new ideas and concepts we will not be able to provide a custom example. All of the performance metrics that NinjaTrader uses are available to view and study through the NinjaScript Editor.

        Please let me know if I can assist any further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        95 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        50 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        31 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        35 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        72 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X