ReloadAllHistoricalData()

View as Markdown

Definition

To be used only in the OnConnectionStatusUpdate() event. Forces the data repository to be reloaded for any bars series running in the hosting script after. Data will be reloaded for any charts currently running which match the hosting scripts bars series (minute, tick, day). This method will also check and reload the max number of days or bars to load used in every chart running which matches the bars series contained in the script. Reloading historical data refreshes the UI which will force the NinjaScript object to re-transition to real-time. This method was designed for reloading historical data after an OnConnectionStatusUpdate event.

Critical: This method should NOT be called from any of the event methods which access data or any of the OnStateChange() states as it may be called recursively while the hosting object transitions through states. The designed use case for this method is reloading historical data after a connection update therefore we suggest ONLY using this method in the OnConnectionStatusUpdate method. Please see the examples below for a demonstration of the intended use case.

Method Return Value

This method does not return a value.

Syntax

ReloadAllHistoricalData()

Parameters

This method does not take any parameters.

Examples

1//monitor our connection status so our NinjaScript object would know to reload historical data
2//create a bool which tracks when historical data would need to be reloaded after a connection loss
3private bool IsReloadAllHistoricalDataNeeded = false;
4protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
5{
6 //if the connection status update detects a lost connection
7 if(connectionStatusUpdate.Status == ConnectionStatus.ConnectionLost)
8 {
9 Print("Connection Lost, setting IsReloadAllHistorical Data to true");
10 // switch the reload data bool to true
11 IsReloadAllHistoricalDataNeeded = true;
12 }
13 // only if we needed to reload historical data && only after when we have reconnected
14 else if (IsReloadAllHistoricalDataNeeded && connectionStatusUpdate.Status == ConnectionStatus.Connected )
15 {
16 Print("Connection is reconnected, reloading all historical data");
17 //then reload data and set our bool back to false.
18 ReloadAllHistoricalData();
19 IsReloadAllHistoricalDataNeeded = false;
20 }
21}