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!
See more
See less

Partner 728x90

Collapse

Pause processing until Fundamental Data received

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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:
    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);
            }
    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?

    #2
    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

    Comment


      #3
      Is there a way to pause OnBarUpdate until sharesOutstanding is not equal to 0? I just need to wait until the sharesOutstanding variable has been set by OnFundamentalData() so I can use shareOutstanding variable on my Historical bars.

      Comment


        #4
        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
        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.


        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          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


            #6
            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


              #7
              Thanks Jesse. Just so I'm clear, what is the easiest way to loop back over the main bars object to reprocess?

              Comment


                #8
                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]);
                    }
                
                }
                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].

                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 NinjaTrader_Manfred  
                Started by wzgy0920, Today, 09:53 PM
                0 responses
                3 views
                0 likes
                Last Post wzgy0920  
                Started by Rapine Heihei, Today, 08:19 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by Rapine Heihei, Today, 08:25 PM
                0 responses
                6 views
                0 likes
                Last Post Rapine Heihei  
                Started by f.saeidi, Today, 08:01 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X