Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

State return value Realtime even when the data are historical

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

    State return value Realtime even when the data are historical

    Hi!
    I just finished my indicator, and inside i have a code, which has to run ONLY on RealTime data NOT on Historical. When i test, only the indicator - works fine. The problem appear when i try to use the indicator from inside a strategy. Then the State return all the time that the data are RealTime even for the first bar which is a few day earlier. I tested the effect with a very simple custom made indicator, and as soon i use it from a strategy the result for State is RealTime All the time for each bar. Is that a bug in NT8, or...The code is very simple:
    Indicator:
    public class MyCustomIndicator : Indicator
    {
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    if (State != State.Historical)
    Print("This is NOT Historical Data Bar N: "+ CurrentBar);
    else
    Print("This is Historical Data Bar N: " + CurrentBar);

    }
    ......................................
    The strategy cod:
    }
    else if (State == State.Configure)
    {
    AddChartIndicator(MyCustomIndicator());
    }

    When I apply only the Indicator to the chart everything is OK, When i call the Indicator from the strategy.....All the bars appear to be in RealTime State!!!!!!

    Please help.
    Thank You.
    Last edited by krasisoft; 12-23-2015, 10:09 AM.

    #2
    I just tested, the same scenario on NT7, and there is not a problem. It is working, as it suppose to work. I think the problem is with NT8. Please find me the solution.. I can not continue with this error....
    Thank You.

    Comment


      #3
      Hello,

      Thank you for the post.

      I do see this on my end as well, it appears only as a Hosted indicator it is displaying Realtime for the State, I could re produce this by printing the State object in OBU.

      I will submit this to development for further review.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Thank you for the answer. Could you please, suggest some way to work around the problem to be able to continue with my strategy development until the fix of the problem.

        Thank you.

        Comment


          #5
          Hello,

          For testing you could use the following syntax, the Bar Count could be used initially to check if the bar being processed is the Count of the series, if so the next bar should be realtime. This is effected by Calculate so that needs to be accounted for in the Count.



          Code:
          bool realtime;
          protected override void OnBarUpdate()
          {
          	if(CurrentBar == 0)
          	{
          		realtime = false;	
          	} 
          	else if(!realtime && CurrentBar == Count - (Calculate == Calculate.OnBarClose ? 2 : 1))
          	{
          		realtime = true;
          	} else {
          		if(realtime)
          		{
          			Print("RealTime");	
          		} else {
          			Print("Historical");	
          		}
          	}
          }

          Please let me know if I may be of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thank You for the code. A did it in other way, but yours is better solution

            Comment


              #7
              Hello,

              I wanted to reply on this topic as it seems this would be expected as you are not actually calling the indicator on historical bars from the strategy.

              In the case of a indicator being hosted by a strategy, you would still need to execute the indicator from OnBarUpdate for it to call the historical bars in the hosted indicator.

              Using what you provided should only need a minimal modification to correct:

              Code:
              public class MyCustomIndicator : Indicator
              {
              protected override void OnBarUpdate()
              {
              //Add your custom indicator logic here.
              if (State != State.Historical)
              Print("This is NOT Historical Data Bar N: "+ CurrentBar);
              else
              Print("This is Historical Data Bar N: " + CurrentBar);
              
              }
              ......................................
              The strategy cod:
              }
              else if (State == State.Configure)
              {
              AddChartIndicator(MyCustomIndicator());
              }
              In this example, you would need to add into OnBarUpdate in the strategy:

              double dummy = MyCustomIndicator()[0];

              Basically just call the indicator from OnBarUpdate in the strategy, you don't need to access its value or anything just calling it would be sufficient to trigger the Historical states.

              Please let me know if I may be of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thank You for the reply.
                i did put the AddChartIndicator() in State.configure, and I'm calling the indicator on each tick in OnBarUpdate.....and here is the problem.
                Let me clarify the problem:
                The strategy actually relay on the data, received from the indicator. And, if the indicator calculate a historical data, it will crash. If the indicator can not recognize, that the Bar0 is historical, and it is treated it, as a RealTime data, all the logic inside crashed. Even you make empty call (not need anything from it) to the indicator it will pass all the calculations anyway and will be the same situation - will calculate historical data, as a RealTime and will crash... I tested this situation many times, and it is not the solution. I think that there is problem within the code and the State of the strategy affect somehow the state value of the indicator (Indicator.State = Strategy.State). The indicator State get the value of the strategy State.
                Thank You.
                p.p. I took all the critical code from the indicator, and put it in the strategy code, but like that, i missed many features, i made inside the indicator, and the strategy code became unnecessary too large
                Last edited by krasisoft; 12-30-2015, 08:40 AM.

                Comment


                  #9
                  Hello,

                  Thank you for the reply.

                  I am unsure on your reply as I am not able to reproduce this, could you provide a sample that demonstrates what you are saying? That would be best in this case so I could run the script as you are on my end to see what you are saying.

                  I have attached the sample that I used, it simply passes the High from the indicator to the strategy and plots it. The AddChartIndicator adds the indicator which is the red plot being plotted from the indicator, the Gold is the strategy plotting the indicators value. I can see both on my end meaning I can see the historical bars being pulled from the indicator and can confirm that with the State print as well.

                  Please let me know if I may be of further assistance.
                  Attached Files
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hi!
                    I made a small modification in you code to demonstrate the problem. I just want to mentioned, that the same code works without any problem in NT7 (see the attachment).

                    p.p. I can easy make this code to work(for example i can exclude Bar 0), but this is not the main point. The point is that the State returns value which is not the right one. Even in your original code you will see that the first pass all bars are Historical state and the second pass all bars are RealTime, which makes non sense... You can not miss the problem now.
                    Thank You

                    Edit: The calculate has to be: Calculate = Calculate.OnEachTick; //!!
                    Attached Files
                    Last edited by krasisoft; 12-30-2015, 12:18 PM.

                    Comment


                      #11
                      Hello,

                      Thank you for providing the sample to confirm what you are asking.

                      I will review this item and reply back once I have explored this further.

                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Hi!
                        Did You find any solution so-far?
                        Than You.

                        Comment


                          #13
                          Hello,

                          Thank you for the reply.

                          I see from the note in the indicator that you are getting an exception by accessing 1 bars ago without first checking if there is data in that index. In general any BarsAgo check you use should be accompanied by also checking that there is enough data in any case to ensure the script performs exactly as it should.

                          The file that was attached would be expected to throw an exception as you are not checking that a bar exists before accessing its using a BarsAgo, although that is not currently what I see when testing this.

                          Have you tested this in the latest beta release? if not I would suggest trying it, I see the print you have added reporting Historical state bars as Historical. Additionally if you remove the Historical check from the indicator I can see that both the strategy and indicator are plotting as expected.


                          Please let me know if I may be of further assistance.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            Hi!
                            Thank You for the answer.
                            It is 3 rows code...can not be more simple then that....Plus the strategy code (1 row) of course.

                            protected override void OnBarUpdate() {
                            if (State != State.Historical) {
                            Value[0] = High[1]; }
                            Print("Bar N: " + CurrentBar + " Has State = " + State);}

                            0 - Let assume that we have a live feedback connection and 5min. Chart for 2 days!!!
                            1 - The error will appear ONLY for the Bar[0] IF THE STATE of Bar[0] is RealTime !!! ----> Is that clear ? Do You agree with me ?
                            2 - When do You expect Bar[0], to be with state RealTime ?? According to my opinion Bar[0] will be RealTime ONLY if there is not any historical data, but We have 5min chart for 2 days ==> Bar[0] is from 1 day ago and it is CLEARLY Historical, and will NEVER execute the code:<<< Value[0] = High[1] >>> !!! --> Do You agree with me? It is not a question do i check if there is enough bars or not, in that example, i know what i have as an input and what i should expect as a result.
                            3 - Do You agree with me, that when we have 5min chart for 2 days period, the state of Bar[0] CAN NOT BE RealTime ?????
                            I can not explain it better then that,. If You say there is no problem, i will give up. I already moved all my code to NT7, but I'm trying to help you to improve the platform. The new NT8 is a great idea and i want to see it ASAP in real life.

                            <<< Have you tested this in the latest beta release >>> -- No i did not. I will test it tomorrow.


                            Thank You in advance
                            Last edited by krasisoft; 02-06-2016, 11:10 AM.

                            Comment


                              #15
                              I just tested with the new NT8 beta, and there is another BUG. The situation for the state is unchanged(the error from above is still there) PLUS NT8 doesn't even recognize that there is no enough candles. I put Value[0] = High[5] and there is no error. From Bar[0] to Bar[5], it returns some random value.
                              I just realized something: Do You use VisualStudio to Debug the code, or You watch only the Output window? If You use the VisualStudio debuger there is no way You miss the problem.

                              Thank You.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              45 responses
                              3,992 views
                              3 likes
                              Last Post johntraderuser2  
                              Started by TAJTrades, Today, 09:46 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post TAJTrades  
                              Started by rhyminkevin, Yesterday, 04:58 PM
                              5 responses
                              62 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Started by realblubb, Today, 09:28 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post realblubb  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              1 response
                              19 views
                              0 likes
                              Last Post Rikazkhan007  
                              Working...
                              X