• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Set initial capital for a strategy

  • Filter
  • Time
  • Show
Clear All
new posts

    Set initial capital for a strategy

    I have a working strategy that I would like to backtest with the following parameters:

    initial capital = $10,000
    only 1 trade per direction
    Each Trade to use maximum account buying power

    How can I program the strategy with the above parameters to see what the Historical return would be?
    Last edited by afshinmoshrefi; 04-21-2017, 06:01 AM. Reason: better description


    Thank you for the post.

    In historical modes, this would be an item you would need to calculate yourself based on fill information that you receive.

    The easiest solution would likely be to create an input for your initial capital:

    EntriesPerDirection is already an option which would allow you to control the Entries in a single direction: http://ninjatrader.com/support/helpG...sub=entriesper

    For your entry logic, you could use the value you have input in your calculations based on the fill information, I would suggest starting by reviewing the example here: http://ninjatrader.com/support/forum...ead.php?t=7499

    This example shows how to use OnExecutionUpdate which would be needed. With the override, you could calculate a value based on the input you had created earlier and store it to a variable. Your entry logic could then reference that variable to calculate the new quantity.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service


      I'm a little confused on use of OnExecutionUpdate event.
      1) I will create a new variable capital and initialize it capital = 10,000.
      2) the share quantity for trade should be q = (int)(capital/Close[0])
      3) profitOrLoss = Close[0] - Close[barsAgo]
      4) capital = capital + profitOrLoss * q
      5) go to step 2) at start of next trade

      The definition in the docs for OnExecutionUpdate() is :
      An event driven method which is called on an incoming execution of an order managed by a strategy. An execution is another name for a fill of an order.

      How can I set the quantity after the execution of the order?

      I would have thought to setup the quantity q on OnBarUpdate and recalculate capital with OnExecutionUpdate()

      However I want to exit the old trade, recalculate the new quantity and enter the reverse order on the same bar with a different q - how can I do that?

      Shouldn't this calculation of capital and q be done OnBarUpdate?
      Last edited by afshinmoshrefi; 04-24-2017, 06:27 PM.



        Thank you for the reply.

        It would really depend on when you need to calculate the value in your logic. OnExecutionUpdate would generally be used to do things like this as you would have the most updated information about the execution as it was reported instead of potentially waiting in OnBarUpdate.

        OnExecutionUpdate can be used solely for setting variables or to do other logic based on the fill of an order. For example, after a fill occurs you could update the capital variable and calculate a new quantity which could also be stored as a variable. From OnBarUpdate in your overall logic, you can reference the capital and quantity variables for the next entry when it should occur. You could also calculate the quantity from OnBarUpdate and only adjust the capital from OnExecutionUpdate, it really depends on how you want to form it.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service


          Since I am interested in Historicals only, I can just use OnBarUpdate. I have programmed this sequence which seems to work. I am using :
          Position.GetUnrealizedProfitLoss(PerformanceUnit.P oints, Close[0]) to get the gain or loss from the trade. However I the value of GetUnrealizedProfitLoss does not seem to match

          (Close[0] - Close[barsAgoTradeStart]) * quantity should = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency

          but there is a small difference. Why are these different?



            Thank you for the reply.

            It would be difficult to say from what has been provided what may be different.

            How are you currently setting the barsAgoTradeStart? Is this accurately the same fill price as the entry? Potentially if you are using the Close of the bar but the fill price is different, that would cause differences. This may be one other reason for using OnExecutionUpdate as you have the average fill price of the order opposed to the Close price of the bar the order was on.

            Also which syntax are you using for the, are you using the following or supplying a price as well?
            Supplying a price:

            Position.GetUnrealizedProfitLoss(PerformanceUnit.Points, Close[0])
            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service


              I calculated the gain or loss by using the entry and exit prices shown on the chart and multiply by the quantity. When calculating the gain or loss in the strategy I use :

              profitOrLoss = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]);

              They don't match but they are near within $10.


              Latest Posts


              Topics Statistics Last Post
              Started by reedstickets, Today, 07:53 PM
              0 responses
              Last Post reedstickets  
              Started by Atilla, Today, 04:05 PM
              0 responses
              Last Post Atilla
              by Atilla
              Started by Displacer, Today, 02:57 PM
              2 responses
              Last Post Displacer  
              Started by SAILIKITY, 05-22-2019, 05:41 PM
              1 response
              Last Post NinjaTrader_PaulH  
              Started by rmillar, 01-09-2019, 06:02 PM
              6 responses
              1 like
              Last Post eDanny
              by eDanny