private long sharesOutstanding = 0;
protected override void OnFundamentalData(FundamentalDataEventArgs e)
{
if (e.FundamentalDataType == FundamentalDataType.SharesOutstanding){
sharesOutstanding = e.LongValue;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 0)return;
Print(State + " " + sharesOutstanding);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Pause processing until Fundamental Data received
Collapse
X
-
Pause processing until Fundamental Data received
I need the Shares Outstanding value from OnFundamentalData prior to my bars being processed Historically. Here is my code:
The result of this is that it Prints "Historical 0" for every Historical Bar processed and then as soon as the state hits Realtime, it prints "Real Time 932782." However I need the 932732 value during Historical processing. What is the best design pattern for this?Code:Tags: None
-
Hello swcooke,
Thank you for the post.
I don't believe this concept would be possible, the OnFundamentalData is not processed historically so there would not be a way to retrieve that value prior to processing your bars. Because this only works going forward, you would need to do your calculation after the historical bars process. One idea would be to use a for loop to iterate over the historical bars again, at that point if you needed to calculate something for the whole series you could. This may additionally require adding logic to prevent your normal OnBarUpdate actions from running until that is complete.
I look forward to being of further assistance.
-
Hello swcooke,
The OnBarUpdate and other events cannot be paused. You are also looking at this the wrong way, your variable cannot be set in historical at all if you require OnFundamentalData to set it. This override is not run for historical bars, so there is no chance the variable will be able to be set like you are asking. Realtime only starts once your historical bars have been processed.
For what you are describing the best solution will be to return until you are ready:
When you set sharesOutstanding, going forward in realtime it would be able to be used. If you needed this value to do something with the historical bars, you could now do that after setting the value. Generally you would use a loop if you needed to re-process the historical bars that already were run through OnBarUpdate.Code:OnBarUpdate if(sharesOutstanding == 0) return; // do logic that requires sharesOutstanding here
I look forward to being of further assistance.
Comment
-
It does not seem very flexible that fundamental data would not be somehow available to historical bars. The data is just static data so I just need to call for it once and stick it into a variable somehow. I don't need to call it on every historical bar. Are you sure there is not some design pattern the the NT developers had in mind to allow for this?
If the answer above is no, is there a way for my script to reload itself? Sort of like the equivalent of me pressing F5 from the chart? If so, I could check for the presence of a text file when the indicator loads and if there isn't one that has this info in it, I could write the fundamental data I need to a file from inside the OnFundamentalData block and then reload everything which would load fine since the file would be there.
Comment
-
Hello swcooke,
For the value you are trying to get that would be the only way. The override being used is specifically for realtime only, this is not like Historical Data where you can query for the data. I couldn't really suggest anything else there aside from what I already have.
There is not a way to reload the chart from NinjaScript as that would affect all scripts, not just yours. This would be something you could manually reload if needed, otherwise the best solution is still to just loop over the data if you need to reprocess it once you get the value.
I look forward to being of further assistance.
Comment
-
Hello swcooke,
You can use a standard for loop and utilize the Count or the CurrentBar depending on what you needed to calculate and which direction you wanted the loop to run.
for example lets assume that the below sample happens when your variable has been populated and in realtime:
This is a backwards loop from the past to the present. Assuming this was executed after you get your value you can reprocess the bars again. the variable i would be the BarsAgo to use in place of CurrentBar in the calculations as shown above with Time[i].Code:if(State == State.Realtime && sharesOutstanding > 0 ) { for(int i = CurrentBar; i > 0; i--) { Print(Time[i]); } }
I look forward to being of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
571 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
331 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
549 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
549 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment