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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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:
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.JesseNinjaTrader Customer Service
-
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:
Code:OnBarUpdate if(sharesOutstanding == 0) return; // do logic that requires sharesOutstanding here
I look forward to being of further assistance.
JesseNinjaTrader Customer Service
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.
JesseNinjaTrader Customer Service
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:
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.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mgco4you, Today, 09:46 PM
|
1 response
3 views
0 likes
|
Last Post Today, 09:56 PM | ||
Started by wzgy0920, Today, 09:53 PM
|
0 responses
3 views
0 likes
|
Last Post
by wzgy0920
Today, 09:53 PM
|
||
Started by Rapine Heihei, Today, 08:19 PM
|
1 response
8 views
0 likes
|
Last Post Today, 08:30 PM | ||
Started by Rapine Heihei, Today, 08:25 PM
|
0 responses
6 views
0 likes
|
Last Post Today, 08:25 PM | ||
Started by f.saeidi, Today, 08:01 PM
|
1 response
9 views
0 likes
|
Last Post Today, 08:17 PM |
Comment