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

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

    Leave a comment:


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

    Leave a comment:


  • afshinmoshrefi
    replied
    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?

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


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

    Leave a comment:


  • afshinmoshrefi
    started a topic Set initial capital for a strategy

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by ghoul, Today, 06:02 PM
2 responses
12 views
0 likes
Last Post ghoul
by ghoul
 
Started by jeronymite, 04-12-2024, 04:26 PM
3 responses
44 views
0 likes
Last Post jeronymite  
Started by Barry Milan, Yesterday, 10:35 PM
7 responses
20 views
0 likes
Last Post NinjaTrader_Manfred  
Started by AttiM, 02-14-2024, 05:20 PM
10 responses
180 views
0 likes
Last Post jeronymite  
Started by DanielSanMartin, Yesterday, 02:37 PM
2 responses
13 views
0 likes
Last Post DanielSanMartin  
Working...
X