Helpguide for TriggerCustomEvent includes sample code with the below lines:
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);
}
- 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?
- Are Close, High, etc series up-to-date within PrintThePrice?
- 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:
- 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.
- 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
Comment