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

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, 06: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 guidoisot, Today, 03:01 AM
    0 responses
    2 views
    0 likes
    Last Post guidoisot  
    Started by rontronimous, Yesterday, 05:55 PM
    0 responses
    9 views
    0 likes
    Last Post rontronimous  
    Started by bcgeek, Yesterday, 03:43 PM
    2 responses
    8 views
    0 likes
    Last Post bcgeek
    by bcgeek
     
    Started by Mberg, Yesterday, 04:05 PM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_ChrisSch  
    Started by dkbyond, Yesterday, 03:52 PM
    0 responses
    5 views
    0 likes
    Last Post dkbyond
    by dkbyond
     
    Working...
    X