Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TiggerCustomEvent and internal Series<T>

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    TiggerCustomEvent and internal Series<T>

    Dear NT team,

    Helpguide for TriggerCustomEvent includes sample code with the below lines:
    // This is the method to run when the timer is raised.
    privatevoidTimerEventProcessor(ObjectmyObject,EventArgsmyEven tArgs)
    {
    // Do not process your code here but instead call the TriggerCustomEvent() method
    // and process your code in the custom handler method e.g., our custom PrintThePrice()
    // Doing so ensures all internal indexers are up-to-date
    TriggerCustomEvent(PrintThePrice,Close[0]);
    }
    ...
    // Print the latest closing price with the current time
    privatevoidPrintThePrice(objectprice)
    {
    Print("The Last Bar's Closing Value as of "+NinjaTrader.Core.Globals.Now+" was "+price);
    }
    I have some performance-related Qs on the above:
    1. As per the Helpguide, internal series are brought up-to-date when a custom event is triggered. In the example, however, Close[0] is passed on as a parameter from within a Timer event (ie, it sits "above" the custom event which TriggerCustomEvent initiates). Is Close[0] guaranteed to be up-to-date when used in this way, as in the example?
    2. Are Close, High, etc series up-to-date within PrintThePrice?
    3. Are there any performance related considerations why Close in the example is passed on as a parameter, rather than accessed from PrintThePrice?

    The context is that I need to access up-to-date Close[0], High[0] and Low[0] outside of OBU (and the other "market data" methods). This has to be a CPU-efficient. What is the best way then?

    In case that changes anything, I do not need the whole series price to be up-to-date when accessed. Just the latest [0] values.

    Now, it is perhaps easy to say that I can store High[0], Close[0], Low[0] from within OBU into global vars. This seems to depend on when the Series<T>[0] are updated / are up-to-date:
    1. Are Close[0], High[0] etc values generally up-to-date outside of market-data methods (OBU) anyway (as opposed to the whole Series)? If so, I should be able to access them in non-market methods without using TriggerCustomEvent.
    2. If the answer to the above is "No, these values are not up-to-date", then at what point Close[0]. etc are internally updated when compared to the time when OBU fires? In other words, is it possible that Close[0] is updated in a custom event but OBU has not processed on these updated values yet?

    To be clear, I am referring to an OBU which is run on each tick.

    Thank you,
    Roman
    Last edited by roman_ch; 02-10-2018, 09:22 AM.

    #2
    Hello,

    Thank you for the post.

    #1. The value passed in should be the same as what you see from inside the custom event void in regard to using Close[0], this was just used to demonstrate passing in a value.

    #2 yes this is what the help guide means when the pointers are synced, without using TriggerCustomEvent the values would not be able to be accessed correctly.

    #3 no as noted this is to demonstrate passing a value to the method, you can access the series and other NinjaScript properties from the void method.

    The context is that I need to access up-to-date Close[0], High[0] and Low[0] outside of OBU (and the other "market data" methods). This has to be a CPU-efficient. What is the best way then?
    Generally, it is suggested to use direct indexes instead of BarsAgo when you are out of the event driven context. For anything that happens at a very high frequency, I would suggest using a variable or the Get methods instead of TriggerCustomEvent. There is an example of using the Get methods in the OnRender documentation but this concept can be used anywhere you are out of the event driven context:


    If you are unable to calculate the index of the bars you want to reference, you may instead use TriggerCustomEvent but that is certainly more than just calling a single series by its index.

    In case that changes anything, I do not need the whole series price to be up-to-date when accessed. Just the latest [0] values.
    If you only need the current value, you may be better off just creating private variables for that purpose and updating their values from OnBarUpdate. This would certainly be the most efficient way and least logic used.

    Regarding your other two items, I believe these should be answered with the statements above but I will elaborate further.

    #1, no anything that uses a BarsAgo or is inherited by the script will not be in sync with any out of the event-driven methods. You would need to use a private variable (preferred, most simple), the Get methods (preferred) or TriggerCustomEvent.

    #2, the various inherited properties would be updated before/when OBU is called, that would be the reason it is called or that a bar has closed which will present new information to the script. At no point will this information be updated outside of the standard data overrides, this information is only specific to the data event overrides. In your case, you likely want to either store the values from OBU and then later access those, use the Get methods with a specific index (CurrentBar stored to a variable) or the TriggerCustomEvent to sync the inherited properties values with "now" listed in the order most preferred over least preferred.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks, Jesse. Great answer, all clear.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by habeebft, Today, 07:27 AM
      0 responses
      4 views
      0 likes
      Last Post habeebft  
      Started by Tim-c, Today, 03:54 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by rocketman7, Today, 01:00 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by wzgy0920, 04-23-2024, 09:53 PM
      3 responses
      76 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by JonesJoker, 04-22-2024, 12:23 PM
      9 responses
      46 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X