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


Filtering Historical from RealTime data for indicators running in Market Analyzer

  • Filter
  • Time
  • Show
Clear All
new posts

    Filtering Historical from RealTime data for indicators running in Market Analyzer

    I'm converting from Ninja 7 to NT8 ....

    In NT7 the boolean Historical always worked well for me...

    But now, in NT8, I use a bool that is initialized to false and then set to true in State.RealTime (opposite of NT7 Historical, true when real time data)

    but that doesn't seem to work...

    I have about 5 indicators that all have this behavior in NT8 -- I cannot tell Historical data from RealTime

    in each I put this in State.SetDefaults because I was told that without a plot an indicator in Market Anayzer will have no real time data?

    // Needed so that Market Analyzer has RealTIme data ??
    AddPlot(Brushes.Transparent, "Needed for Market Analyzer to have RealTIme Data");​

    When the same indicator runs on a Chart, I can filter the Historical from Real Time data.


    Hi, thanks for writing in. We can filter by real-time and historical in OnBarUpdate like this with a plot added. Each script will reach the State.Transition state when it transitions from historical to real time in OnStateChanged. To filter in OnBarUpdate you can use this code to test it.

    protected override void OnBarUpdate()
    if(State == State.Historical)
    if(State == State.Realtime)

    Kind regards,
    Chris L.NinjaTrader Customer Service


      Can I then use if(State == State.Historical) in NT8 the same way as if (Historical) in NT7


        Ok, well, I must be hallucinating .... can you please run the attached indicator against, say a 1 minute NQ chart, and then also the same in MarketAnalyzer

        I'm sure I'm doing something totally stupid...but this shows what I'm talking about

        In Market Analyzer, if (State == State.Historical) return; does not do anything. It works as expected on a chart...that is, it filters out the Historical data

        Attached Files


          Ok, well it appears it is a coder (that is me) error.

          When I add the ploot in State.Configure the script acts as expected.

          Que tonto, yo..... :-)


            There was a bug in the above CS uploading again (sorry I'm tired from the NT conversion effort)

            When I changed it from OnBarClose to OnPriceChange I don't get any RealTime Data in Market Analyzer... Chart is OK

            Now it has gone back to the behavior prior, even OnBarClose there is not Market Analyzer data...should I upload Market Analyzer templates?

            In the Market Analyzer Properties Window, there is a field for Plot.....this field is empty and there is nothing in the drop down....

            Is that supposed to be the Plot that I added?

            Maybe the Plot needs to be changed?

            Attached Files


              Hi llanqui, the AddPlot() should be called in State.SetDefaults so it will show up in the UI.

              Please let me know if this does not resolve.
              Chris L.NinjaTrader Customer Service


                for the moment I'm going to run these indicators on a chart...then will come back to this issue....thanks


                  Well, it seems it is not enough to AddPlot but it also needs to be assigned values ....seems to me to be a waste of memory resources..


                    Have you found a solution ?


                      No, not yet...I had to finish a big port from NT7 to NT8....when that is stable I will revisit this....

                      but what I do now is to run these indicators on a chart in a background workspace....that works like expected

                      was not an issue in NT7....


                        Hola Yankee,
                        I should have been specific, "Filtering Historical from RealTime data for indicators running in Market Analyzer​", is what I was asking about.
                        I may be able to help with the other issues, if you need it.
                        Not going back & reading all the posts, I'll do a short "file dump":
                        NT 8 only.
                        I'm running it on the ES, very liquid, many price changes.
                        My solution works on​ "Calculate.OnPriceChange", it does NOT work on "Calculate.OnBarClose".
                        A Market Analyzer (MA) state, once it gets to OnBarUpdate(), is always ".State.Realtime".
                        However, when it's "Historical", it runs like it's on "Calculate.OnBarClose", one bar.
                        Once it gets to "Realtime", there are bars every price change.
                        The filter, run in OnBarUpdate() :

                        if (Time[0] == TimePrior)
                        {RealTimeFlag = true;}
                        TimePrior = Time[0];

                        ​RealTimeFlag is your bool.

                        I just came up with this a few days ago, after going through it much like yourself, and "sitting on it" for years, but it's working so far.

                        I hope this helps somebody, I hate writing.

                        Adios, llanqui​, from Tejas

                        Last edited by BGWTEX; 01-12-2023, 02:40 PM.


                          I had this response on a new post from NT...

                          Hello, Are there examples of how to use an indicator in a Market Analyzer, so that RealTime data is available to the indicator? Indicator Code and how to set up_ thx


                          Latest Posts


                          Topics Statistics Last Post
                          Started by athexinehowley, Today, 02:39 AM
                          0 responses
                          Last Post athexinehowley  
                          Started by dtaylor, Today, 02:24 AM
                          0 responses
                          Last Post dtaylor
                          by dtaylor
                          Started by RosaRichardow, Today, 12:21 AM
                          1 response
                          Last Post marcus2300  
                          Started by ETFVoyageur, Today, 12:45 AM
                          1 response
                          Last Post ETFVoyageur  
                          Started by TradeSaber, Yesterday, 10:33 PM
                          1 response
                          Last Post TradeSaber