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

correct syntax for determining the max dollar amount of risk

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

    correct syntax for determining the max dollar amount of risk

    Is this syntax correct? I want to calculate the total dollar amount of exposure between the close of the trigger bar to the stop value.

    Both tradeRisk and stop are doubles.

    Instrument.MasterInstrument.PointValue should be the dollar amount in usd of each tick of the instrument in the primary data series.

    long position:

    tradeRisk = ((Close[0] - stop) / (TickSize)) * Instrument.MasterInstrument.PointValue;

    short position:

    tradeRisk = (stop - Close[0]) / (TickSize) * Instrument.MasterInstrument.PointValue;
    Last edited by gordongekko; 03-01-2018, 10:16 AM.

    #2
    Hello gordongekko,

    Thanks for opening the thread.

    In your example you are finding the difference between the current price and your stop level, converting it to ticks and then multiplying it by the instruments point value. I don't think this is what you want to do to see the max dollar amount at risk in a given position.

    I may propose:
    • AverageEntryPrice - StopLoss to get the maximum dollar amount at risk in the position for long entries
    • StopLoss - AverageEntryPrice to get the maximum dollar amount at risk in the position for short entries

    Average entry price can be found for the overall strategy position with Position.AveragePrice, or you can use Order objects for your orders and use AverageFillPrice to get the fill price of your entry orders.

    Position.AveragePrice - https://ninjatrader.com/support/help...erageprice.htm

    Order objects - https://ninjatrader.com/support/help...n-us/order.htm

    Advanced Order Handling (Order class) - https://ninjatrader.com/support/help...#TheOrderClass

    Please see the SampleOnOrderUpdate Strategy as an example for using Order objects - https://ninjatrader.com/support/foru...ead.php?t=7499

    Please let me know if you have any questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      The reason I don't use average entry price is because this calculation is made before a trade decision is made in the first place. If tradeRisk <= MaxRisk then an order is submitted. If not, then the trigger is skipped. This is to filter out trades with an estimated risk that is too large for a particular risk management strategy. Since nothing is getting through my filter it's obvious I did not type it correctly.

      I'll make it more clear what I'm trying to accomplish here.

      Basically I need to know 2 things.

      1. Does Instrument.MasterInstrument.PointValue == the usd $ amount of each tick of the primary data series

      2. Is below syntax correct and if not can you please provide the correct syntax.

      The result of A divided by B multiplied by C

      A = Close[0] - stop
      B = TickSize
      C = Instrument.MasterInstrument.PointValue

      tradeRisk = ((Close[0] - stop) / (TickSize)) * Instrument.MasterInstrument.PointValue;

      or

      tradeRisk = ((Close[0] - stop) / TickSize) * (Instrument.MasterInstrument.PointValue);
      Last edited by gordongekko; 03-01-2018, 11:00 AM.

      Comment


        #4
        Hello gordongekko,

        I would recommend then using Close[0] instead of the average entry price of an order to project a potential entry price. You may want to add a variable for slippage so you can include potential slippage in your risk calculation. For example: Slippage * TickSize, where Slippage is a parameter you have created for potential slippage.

        I am not sure why you want to use TickSize and PointValue when you already have the dollar amounts needed to calculate a max potential loss with the "potential entry price" and the stop loss price for that position.

        1. Does Instrument.MasterInstrument.PointValue == the usd $ amount of each tick of the primary data series
        No, PointValue indicates the currency value of 1 full point of movement. For example, 1 point in the S&P 500 Emini futures contract (ES) is $50 USD which is equal to $12.50 USD per tick. To draw a bigger picture, PointValue/TickSize would be the price per tick. If you already have dollar amounts, I recommend keeping the calculation with dollar amounts and to avoid converting the amount to ticks or points.

        2. Is below syntax correct and if not can you please provide the correct syntax.
        What you have written looks fine. When you use constants and test the code, do you see the results you are expecting in the equation?

        For example, does the following equation evaluate to 10?
        Code:
        tradeRisk = ((10 - 2) / (4)) * 5;
        Print(tradeRisk);
        If there is anything else I can do to help, please let me know.
        JimNinjaTrader Customer Service

        Comment


          #5
          ok so that's where the problem is. I thought the point value was the tick value which explains why nothing was getting through that filter.

          Comment


            #6
            Is there a way to access the us dollar amount per tick of each contract as a variable when making strategies/indicators. The reason this is useful is to create $ amount filters that are universally applicable when you trade a bunch of unrelated instruments with carrying point values.Obviously this value could easily be obtained by dividing the point value by the number of ticks in a point for a specific contract but it would be nice to have access to this value with a simple variable.

            Comment


              #7
              Hello gordongekko,

              This isn't offered, but you could calculate that value for a private variable in State.DataLoaded so it is calculated only once, then reuse that variable as needed throughout your script.
              JimNinjaTrader Customer Service

              Comment


                #8
                That's a good idea. This allows to adapt to whatever instrument is being loaded.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by inanazsocial, Today, 01:15 AM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Jason  
                Started by rocketman7, Today, 02:12 AM
                0 responses
                10 views
                0 likes
                Last Post rocketman7  
                Started by dustydbayer, Today, 01:59 AM
                0 responses
                2 views
                0 likes
                Last Post dustydbayer  
                Started by trilliantrader, 04-18-2024, 08:16 AM
                5 responses
                23 views
                0 likes
                Last Post trilliantrader  
                Started by Davidtowleii, Today, 12:15 AM
                0 responses
                3 views
                0 likes
                Last Post Davidtowleii  
                Working...
                X