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 junkone, Today, 11:37 AM
    0 responses
    2 views
    0 likes
    Last Post junkone
    by junkone
     
    Started by quantismo, 04-17-2024, 05:13 PM
    5 responses
    34 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by proptrade13, Today, 11:06 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    34 views
    0 likes
    Last Post love2code2trade  
    Started by cls71, Today, 04:45 AM
    2 responses
    10 views
    0 likes
    Last Post eDanny
    by eDanny
     
    Working...
    X