• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set initial capital for a strategy

Collapse
X
  • 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

    #2
    Hello,

    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:
    http://ninjatrader.com/support/forum...ead.php?t=5782

    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

    Comment


      #3
      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 :
      Definition
      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.

      Comment


        #4
        Hello,

        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

        Comment


          #5
          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?

          Comment


            #6
            Hello,

            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?
            Code:
            Position.GetUnrealizedProfitLoss(PerformanceUnit.Points)
            Supplying a price:

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

            Comment


              #7
              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.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by yhiiffln, Today, 12:42 AM
              0 responses
              2 views
              0 likes
              Last Post yhiiffln  
              Started by Vincere, Yesterday, 11:20 PM
              0 responses
              3 views
              0 likes
              Last Post Vincere
              by Vincere
               
              Started by lMagi, 05-18-2019, 09:34 AM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by uday12, Yesterday, 10:26 PM
              0 responses
              2 views
              0 likes
              Last Post uday12
              by uday12
               
              Started by uday12, Yesterday, 10:07 PM
              0 responses
              0 views
              0 likes
              Last Post uday12
              by uday12
               
              Working...
              X