• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Message sent out when data is historical

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

    Message sent out when data is historical

    Hi

    I have an issue with an indicator. Whenever a special condition arises, a message should be sent out, however not within historical data.

    I have set the following check:

    if (State != State.Historical)

    Messages will be sent out anyway, no matter what state the data bar has.
    What's the correct way to prevent this?

    #2
    Hello,

    Thank you for the post.

    I have made a sample indicator that will only print out a message in real time. Please compare your script to mine to check for differences. If this does not resolve the issue please post a snippet of your condition.

    Please see the following page for instructions on importing a script:
    https://ninjatrader.com/support/help...us/?import.htm

    I look forward to hearing of your results.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I have change the state from != State.Historical to == State.Realtime.
      I assume that now, only messages are sent out when the candle is in the real time state or is this different?

      protected override void OnBarUpdate()
      {
      SendMailMessage("[email protected]", "Text")
      }

      private void SendMailMessage(string MailRecipient, string Message)
      {
      if (State == State.Realtime)
      {
      if (SendMessageToMail == true)
      {
      SendMail(MailRecipient, Message + " - State is:" + State.ToString());
      }
      }
      }
      Last edited by Sweet&Sour; 12-05-2017, 09:34 PM.

      Comment


        #4
        Hello,

        Thank you for the reply.

        Correct, any logic within if(State == State.RealTime) will be executed only on real-time data.

        You don't have to worry about setting this up though, the help guide page of SendMail() function states that this function will never be called in the State.Historical state.

        1. This method can only be called once the State has reached State.Realtime. Calls to this method in any other State will be silently ignored (in contrast to the implementation for AddOns)
        https://ninjatrader.com/support/help.../?sendmail.htm

        Please let us know if we may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          I saw this in the KB as well however, resizing or refreshing the chart has occasionally triggered historical alerts. Or when the connection has been lost and manually re-establish, old events are also sometimes triggered.

          Personally, I have the impression that there is a bug in NT which is causing this. Obviously the state isn't always correctly handled. Therefore i made a little extension into the message part which also also shows the state when a message get's triggered.

          Comment


            #6
            Originally posted by Sweet&Sour View Post
            I saw this in the KB as well however, resizing or refreshing the chart has occasionally triggered historical alerts. Or when the connection has been lost and manually re-establish, old events are also sometimes triggered.

            Personally, I have the impression that there is a bug in NT which is causing this. Obviously the state isn't always correctly handled. Therefore i made a little extension into the message part which also also shows the state when a message get's triggered.
            Interesting theory. So you believe these old events are firing for historical but reporting as realtime?

            It wouldn't surprise me.

            I would do up a test - but I haven't had TDA chart data in NT8 since 8.0.8.0 for RTH charts.

            Comment


              #7
              It's more a fact than theory :-)
              I've been able to observe such funny mismatches more often in the past. Hence, I log now outgoing messages including time, state, candle id and candle time.

              Comment


                #8
                Hello,

                Thank you for the reply.

                I have made a simple script that confirms the functionality of the State property is nominal. If you have a script that reproduces this error I would be happy to test it out.

                Please let us know if we may be of any further assistance.
                Attached Files
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chris,

                  That's a nice and tiny code snippet which may work all the times. Having much more complexity in the indicator and leaving the indicator running for days or even weeks may give a different result.

                  Just as i said, i have added some additional lines which shows, which candle on which day in which state has produce the signal. Just a few minutes a go, I've got such a signal and a log time stamp was generated which, in this case, was correct.

                  2017-12-07 17:29:59:797|1|16|07.12.2017 11:29:59 CurrentBar is:1759 Current Bar Time is 07.12.2017 05:30:00 State is:Realtime

                  Comment


                    #10
                    Hello,

                    Thank you for the reply.

                    If you could provide an example script that does this I could try to reproduce the issue on my computer.

                    I look forward to your reply.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chris,

                      Today, I have resized my chart an the indicator started to send you a bunch of "old messages". They are all from the past but the state is always realtime. Here are the details. How can this happen in a simple 60 min. Chart of XBI?

                      2017-12-11 18:38:58:690|1|16|12.12.2017 12:38:58 CurrentBar is:22 Current Bar Time is15.12.2016 05:30:00 State is:Realtime
                      2017-12-11 18:38:59:357|1|16|12.12.2017 12:38:59 CurrentBar is:56 Current Bar Time is22.12.2016 04:30:00 State is:Realtime
                      2017-12-11 18:38:59:998|1|16|12.12.2017 12:38:59 CurrentBar is:65 Current Bar Time is23.12.2016 06:30:00 State is:Realtime
                      2017-12-11 18:39:00:547|1|16|12.12.2017 12:39:00 CurrentBar is:93 Current Bar Time is30.12.2016 06:30:00 State is:Realtime
                      2017-12-11 18:39:01:111|1|16|12.12.2017 12:39:01 CurrentBar is:106 Current Bar Time is04.01.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:01:813|1|16|12.12.2017 12:39:01 CurrentBar is:190 Current Bar Time is23.01.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:02:359|1|16|12.12.2017 12:39:02 CurrentBar is:237 Current Bar Time is31.01.2017 10:00:00 State is:Realtime
                      2017-12-11 18:39:02:939|1|16|12.12.2017 12:39:02 CurrentBar is:344 Current Bar Time is23.02.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:03:531|1|16|12.12.2017 12:39:03 CurrentBar is:361 Current Bar Time is27.02.2017 08:30:00 State is:Realtime
                      2017-12-11 18:39:04:154|1|16|12.12.2017 12:39:04 CurrentBar is:470 Current Bar Time is21.03.2017 04:30:00 State is:Realtime
                      2017-12-11 18:39:04:724|1|16|12.12.2017 12:39:04 CurrentBar is:493 Current Bar Time is24.03.2017 06:30:00 State is:Realtime
                      2017-12-11 18:39:05:318|1|16|12.12.2017 12:39:05 CurrentBar is:539 Current Bar Time is04.04.2017 04:30:00 State is:Realtime
                      2017-12-11 18:39:05:952|1|16|12.12.2017 12:39:05 CurrentBar is:568 Current Bar Time is10.04.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:06:590|1|16|12.12.2017 12:39:06 CurrentBar is:574 Current Bar Time is11.04.2017 04:30:00 State is:Realtime
                      2017-12-11 18:39:07:110|1|16|12.12.2017 12:39:07 CurrentBar is:631 Current Bar Time is24.04.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:07:720|1|16|12.12.2017 12:39:07 CurrentBar is:701 Current Bar Time is08.05.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:08:294|1|16|12.12.2017 12:39:08 CurrentBar is:729 Current Bar Time is12.05.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:09:094|1|16|12.12.2017 12:39:09 CurrentBar is:755 Current Bar Time is17.05.2017 10:00:00 State is:Realtime
                      2017-12-11 18:39:09:726|1|16|12.12.2017 12:39:09 CurrentBar is:760 Current Bar Time is18.05.2017 08:30:00 State is:Realtime
                      2017-12-11 18:39:10:252|1|16|12.12.2017 12:39:10 CurrentBar is:801 Current Bar Time is26.05.2017 07:30:00 State is:Realtime
                      2017-12-11 18:39:10:933|1|16|12.12.2017 12:39:10 CurrentBar is:820 Current Bar Time is01.06.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:11:615|1|16|12.12.2017 12:39:11 CurrentBar is:999 Current Bar Time is10.07.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:12:252|1|16|12.12.2017 12:39:12 CurrentBar is:1013 Current Bar Time is12.07.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:12:792|1|16|12.12.2017 12:39:12 CurrentBar is:1108 Current Bar Time is31.07.2017 09:30:00 State is:Realtime
                      2017-12-11 18:39:13:449|1|16|12.12.2017 12:39:13 CurrentBar is:1125 Current Bar Time is03.08.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:14:002|1|16|12.12.2017 12:39:13 CurrentBar is:1156 Current Bar Time is09.08.2017 08:30:00 State is:Realtime
                      2017-12-11 18:39:14:613|1|16|12.12.2017 12:39:14 CurrentBar is:1173 Current Bar Time is14.08.2017 04:30:00 State is:Realtime
                      2017-12-11 18:39:15:246|1|16|12.12.2017 12:39:15 CurrentBar is:1199 Current Bar Time is17.08.2017 09:30:00 State is:Realtime
                      2017-12-11 18:39:16:249|1|16|12.12.2017 12:39:16 CurrentBar is:1216 Current Bar Time is22.08.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:17:000|1|16|12.12.2017 12:39:17 CurrentBar is:1471 Current Bar Time is12.10.2017 08:30:00 State is:Realtime
                      2017-12-11 18:39:17:505|1|16|12.12.2017 12:39:17 CurrentBar is:1547 Current Bar Time is27.10.2017 07:30:00 State is:Realtime
                      2017-12-11 18:39:18:131|1|16|12.12.2017 12:39:18 CurrentBar is:1563 Current Bar Time is31.10.2017 08:30:00 State is:Realtime
                      2017-12-11 18:39:18:728|1|16|12.12.2017 12:39:18 CurrentBar is:1580 Current Bar Time is03.11.2017 04:30:00 State is:Realtime
                      2017-12-11 18:39:19:340|1|16|12.12.2017 12:39:19 CurrentBar is:1602 Current Bar Time is08.11.2017 06:30:00 State is:Realtime
                      2017-12-11 18:39:19:848|1|16|12.12.2017 12:39:19 CurrentBar is:1636 Current Bar Time is15.11.2017 05:30:00 State is:Realtime
                      2017-12-11 18:39:20:334|1|16|12.12.2017 12:39:20 CurrentBar is:1728 Current Bar Time is05.12.2017 09:30:00 State is:Realtime
                      2017-12-11 18:39:20:884|1|16|12.12.2017 12:39:20 CurrentBar is:1738 Current Bar Time is07.12.2017 05:30:00 State is:Realtime

                      There is no magic in the code to send messages. It just a simple void which is called after a trading calculation has been completed.

                      private void OpenClosePositions(GenericTraderMarketPositionType mpType)
                      {
                      switch (mpType)
                      {
                      case GenericTraderMarketPositionType.OpenNewLongPositio n:
                      {
                      if (tradingPosition != GenericTraderMarketPositionTrend.Long)
                      {
                      if (State == State.Realtime)
                      {
                      if (SendMessageToMail == true)
                      {
                      SendMail(MailRecipient, StrategyName + " Trader has changed at " + Time[0].ToString("dd.MM.yyyy hh:mm:ss") + ": Buy " + LongInst + " and Sell " + ShortInst + "", "";
                      }
                      }
                      tradingPosition = GenericTraderMarketPositionTrend.Long;
                      }
                      break;
                      }
                      case GenericTraderMarketPositionType.OpenNewShortPositi on:
                      {
                      ....
                      }
                      }

                      }
                      Last edited by Sweet&Sour; 12-11-2017, 11:03 AM.

                      Comment


                        #12
                        Hello,

                        Thank you for the reply.

                        I am assuming the print statements that print out the CurrentBar, Current Bar Time, and State are within this function you have posted.

                        From where in your script are you calling this function? Is this running from a backtest in the Strategy Analyzer or are these prints from chart loading?

                        If possible please post the code statement that prints the current bar and time and describe the context of the snippet.

                        I look forward to your reply.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChrisL View Post
                          Hello,

                          Thank you for the reply.

                          I am assuming the print statements that print out the CurrentBar, Current Bar Time, and State are within this function you have posted.

                          From where in your script are you calling this function? Is this running from a backtest in the Strategy Analyzer or are these prints from chart loading?

                          If possible please post the code statement that prints the current bar and time and describe the context of the snippet.

                          I look forward to your reply.
                          The print statements that print out the CurrentBar, Current Bar Time, and State are called within this function, right after the message call.

                          The function OpenClosePositions is called from within OnBarUpdate.

                          Log(DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss")
                          + " CurrentBar is:" + CurrentBars[0].ToString()
                          + " Current Bar Time is" + Time[0].ToString("dd.MM.yyyy hh:mm:ss")
                          + " State is:" + State.ToString()
                          , NinjaTrader.Cbi.LogLevel.Information);

                          It's a chart which is open on my desktop. The code has been loaded as an indicator. Please note that in general, real-time message are sent out correctly (which indicates that the code is working as expected). The problem only appears when i resize the chart or when i scroll within the chart from right to left or vice versa.
                          Last edited by Sweet&Sour; 12-12-2017, 01:32 PM.

                          Comment


                            #14
                            Hello,

                            Thank you for the reply.

                            There seems to be an interaction with OnRender(). OnRender() is called during window resize and chart scroll events, among many other chart events. OnRender() is also called in real time only so this has a high probability of conveying what the issue is in this script.

                            Without the syntax of this script, I can not tell what this issue is for certain though.

                            I look forward to hearing of your results.
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              The code is irrelevant because it does what it should....as long as I do not move the window or scroll in it.

                              I personally have the impression that the State does not always what it should do, especially when it leaves the OnBarUpdate method. But the hint with OnRenderTargetChanged / OnRender is usefull.

                              Can you send me a little code snippet in which I can check what happens with the State in OnRenderTargetChanged/OnRender when i resize/scroll the chart window? Capturing some data during resizing/scrolling could already help...

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Erwin Beckers, Today, 01:23 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Erwin Beckers  
                              Started by Mark Taylor, Yesterday, 11:36 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Mark Taylor  
                              Started by Bluebeep, Yesterday, 08:38 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post Bluebeep  
                              Started by stokhastic, Yesterday, 07:08 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post stokhastic  
                              Started by jlkramer16, Yesterday, 04:29 PM
                              1 response
                              5 views
                              0 likes
                              Last Post jlkramer16  
                              Working...
                              X