• 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


Creating an event driven method to evaluate PnL

  • Filter
  • Time
  • Show
Clear All
new posts

    Creating an event driven method to evaluate PnL

    Nt8 has many ways to get PnL intraday info, but all of them must be placed within the OnBarUpdate() to get the job done. My intention is to create or use an "event-driven method" so I don't need overuse OnBarUpdate(). I've searched about OnAccountItemUpdate() and perhaps this could fit.

    A practical problem: Stop the Strategy if daily PnL has reached a limit

    As I wrote at the beginning, yes, NT8 has a way to do this procedure, however, it uses OnBarUpdate() for it, so what I want is an independent event-driven method that detects and stop the Strategy at any moment. So, in order to use OnAccountItemUpdate() as it's shown bellow, I'd need to know:

    protected override void OnAccountItemUpdate(Account account, AccountItem accountItem, double value)
    			if ( Account.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar)+Account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar) <= -Maxlos ) 
    				// do code
    1. Where should this method be located in the code ? before or after OnBarUpdate() ?

    2. Do I need to subscribe to something in order to use this method ?

    3. In the sample above:
    a. Would that snnipet work reliably?
    b.is there a more efficient way ?

    A last important question: using this even-driven method to check account variables, does it use less pc resources than checking PnL variable checking within ObBarUpdate() ?

    I'd highly appreciate any other ideas and suggestions that may help me to figure this out.

    Thanks in advance
    Last edited by pstrusi; 09-22-2017, 07:00 AM.

    Hello pstrusi,

    Thank you for the post.

    1. You may put this function before or after OnBarUpdate(), as long as the function belongs to the indicator/strategy class, the compiler will be able to see it.

    2. No subscription needed, as long as you implement OnAccountItemUpdate() it will be called in the NinjaScript pipeline.

    a. The implementation you have provided will work. The function will be called once a change to the
    account has been made.

    b. This method is essentially the nominal way of receiving account updates.

    The complexity of the code is the factor that affects the performance the most. Comparing the speeds of the two functions would produce negligible differences in performance. With that being said, the OnAccountItemUpdate function will guarantee that your code is updated once an item in the account has changed.

    If questions come up or if we may be of any further assistance, please let us know.
    Chris L.NinjaTrader Customer Service


    Latest Posts


    Topics Statistics Last Post
    Started by lupearadu, Today, 01:58 PM
    0 responses
    1 view
    Last Post lupearadu  
    Started by rexmie888, Today, 01:47 PM
    0 responses
    1 view
    Last Post rexmie888  
    Started by aslane, Today, 12:41 PM
    0 responses
    Last Post aslane
    by aslane
    Started by NinjaCustomer, 06-06-2018, 08:47 AM
    15 responses
    Last Post cls71
    by cls71
    Started by Johnny Santiago, 04-29-2019, 04:13 AM
    3 responses
    1 like
    Last Post bltdavid