TriggerCustomEvent()
TriggerCustomEvent()
Definition
Provides a way to use your own custom events (such as a Timer object) so that internal NinjaScript indexes and pointers are correctly set prior to processing user code triggered by your custom event. When calling this event, NinjaTrader will synchronize all internal pointers and then call your custom event handler where your user code is located.
The TriggerCustomEvent() method does NOT execute before State.DataLoaded or during or after State.Terminated. In effect, attempting to trigger custom events may be unavailable in some circumstances (e.g., while an indicator is terminating, or viewing the Strategy Analyzer chart display after backtest has completed, etc.)
Method Return Value
This method does not have a return value.
Syntax
TriggerCustomEvent(Action\<object\> customEvent, object state)
TriggerCustomEvent(Action\<object\> customEvent, int barsSeriesIndex, object state)
Parameters
Tips:
- There may be scenarios in which you need to set a Series<T> value outside of one of the core data event methods. In these cases, you can use TriggerCustomEvent() to reliably synchronize the barAgo indexer to the recent. current bar being updated. Please see the example below.
- Usually the correct approach is to use the WPF Dispatcher timer, however in cases where you need the timer to update a WinForms window it opened - please use the WinForms timer.

