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

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:


    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 Christopher_R, Today, 12:29 AM
              0 responses
              10 views
              0 likes
              Last Post Christopher_R  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              166 responses
              2,235 views
              0 likes
              Last Post sidlercom80  
              Started by thread, Yesterday, 11:58 PM
              0 responses
              3 views
              0 likes
              Last Post thread
              by thread
               
              Started by jclose, Yesterday, 09:37 PM
              0 responses
              8 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,415 views
              0 likes
              Last Post Traderontheroad  
              Working...
              X