Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating an event driven method to evaluate PnL

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

    Code:
    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.

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

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bill2023, Yesterday, 08:51 AM
    8 responses
    43 views
    0 likes
    Last Post bill2023  
    Started by yertle, Today, 08:38 AM
    6 responses
    25 views
    0 likes
    Last Post ryjoga
    by ryjoga
     
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    24 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    46 views
    0 likes
    Last Post jeronymite  
    Working...
    X