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

Filtering Historical from RealTime data for indicators running in Market Analyzer

Collapse
X
 
  • 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.

    Help!!!

    #2
    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)
    Print("Historical");
    if(State == State.Realtime)
    Print("RealTime");
    }

    Kind regards,
    -ChrisL​​
    Chris L.NinjaTrader Customer Service

    Comment


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

      Comment


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

        Comment


          #5
          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..... :-)

          Comment


            #6
            There was a bug in the above CS file...am 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

            Comment


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

              Comment


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

                Comment


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

                  Comment


                    #10
                    Have you found a solution ?

                    Comment


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

                      Comment


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

                        Comment


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

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          2 views
                          0 likes
                          Last Post Javierw.ok  
                          Started by timmbbo, Today, 08:59 AM
                          2 responses
                          10 views
                          0 likes
                          Last Post bltdavid  
                          Started by alifarahani, Today, 09:40 AM
                          6 responses
                          40 views
                          0 likes
                          Last Post alifarahani  
                          Started by Waxavi, Today, 02:10 AM
                          1 response
                          18 views
                          0 likes
                          Last Post NinjaTrader_LuisH  
                          Started by Kaledus, Today, 01:29 PM
                          5 responses
                          15 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X