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

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,769 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        10 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        7 views
        0 likes
        Last Post rocketman7  
        Working...
        X