Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Realtime state

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

    Realtime state

    Hi,
    i have a strategy that is referencing to an indicator that looks like this:

    Code:
            protected override void OnBarUpdate()
            {
                if (State != State.Realtime) return;
                Print(string.Format("{0}  {1}", State, CurrentBar));
            }
    When I enable the strategy, for some reason indicator starts from 0 bar.

    Code:
    Realtime 0
    Realtime 1
    Realtime 2
    But if I add this indicator to chart (w/o strategy), it starts from actual reatime bar.

    Code:
    Realtime  2702
    Is this normal behavior?

    #2
    Hello Leeroy_Jenkins,

    Thanks for your post.

    Please share an exported copy of the example strategy you are using to replicate this behavior so that I may investigate this matter.

    To export a script, go to Tools > Export > NinjaScript AddOn.

    Exporting: https://ninjatrader.com/support/help...tAsSourceFiles

    I look forward to assisting further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Looks like this behavior only happens with this indicator.
      Attached Files

      Comment


        #4
        Hello Leeroy_Jenkins,

        Thanks for your note.

        First I enabled the indicator you shared on an ES 03-23 1-Minute chart and noted the NinjaScript Output window.

        When enabling the indicator that you shared, I see a print of 'Realtime 1452' in the Output window. Then, I removed the indicator from the chart and enabled the strategy on the same chart.

        See the attached screenshot.

        After enabling the strategy, I see a print in the Output window showing the same print 'Realtime 1452' as well as historical prints showing previous bar values. See attached screenshot.

        If you enable the indicator you shared on an ES 03-23 1-Minute chart, do you see a print stating the current state is Realtime and the CurrentBar number similar to the screenshot I shared?

        If you remove the indicator and enable the strategy on the same chart, do you see the print stating the current state is Realtime and both the realtime CurrentBar number and historical CurrentBar numbers similar to the screenshot attached?

        Please let me know if I may assist further.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          >If you enable the indicator you shared on an ES 03-23 1-Minute chart, do you see a print stating the current state is Realtime and the CurrentBar number similar to the screenshot I shared?

          yes, it's starts from Realtime 2498.

          >If you remove the indicator and enable the strategy on the same chart, do you see the print stating the current state is Realtime and both the realtime CurrentBar number and historical CurrentBar numbers similar to the screenshot attached?

          yes, it starts from Realtime 0.
          Also those outputs start only after price change on chart and not instantly when strategy added. After seeing actual current bar print, try to clear output window, wait until price changes and you'll see again Realtime 0 --> Realtime CurrentBar.

          Comment


            #6
            Hello Leeroy_Jenkins,

            Thanks for your note.

            I am connected to a Live data feed connection and add the indicator to the chart. The indicator prints in the Output window show a print of "Realtime 4579".

            Then the indicator is removed from the chart and I enable the TestStrategy. Once the strategy calculates and loads on the chart, I see the prints in the Output window that states "Realtime <CurrentBar number>" for historical bars. The most recent CurrentBar number is "4580". This is because one bar closed between the time I removed the indicator and enabled the strategy.

            If I let the currently forming bar close, the strategy prints "Realtime 4581" to the Output window. If I let another bar close, the strategy prints "Realtime 4582" to the Output window.

            See this video demonstrating the above comments: https://brandonh-ninjatrader.tinytak...OV8yMTAyMjM5NA

            If you test this on Live data using the same steps in the video, do you see different results?

            Let me know if I may assist further.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              You're missing the point. Look at 2:35-2:36 time of your video. You can see Realtime 142. How is that possible? If you clear output window you gonna see again calculation from bar 0 to current bar. For some reason it recalculates ALL bars at every price change starting from 0 bar.

              Comment


                #8
                Hello Leeroy_Jenkins,

                Your strategy does not call the indicator.

                From the help guide:
                "Tip: If you are adding an indicator which is dependent on the correct State of the indicator, you will need to ensure that you are also calling the indicator from the strategy in OnBarUpdate(), otherwise your indicator will only process in State.RealTime for performance optimizations."
                https://ninjatrader.com/support/help...tindicator.htm

                Call the indicator in your strategy.

                In the scope of the class:
                private PatternBookHelper PatternBookHelper1;

                In State.DataLoaded:
                PatternBookHelper1 = PatternBookHelper("");

                In OnBarUpdate():
                PatternBookHelper1.Update();
                var s = PatternBookHelper1.Signal;
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                51 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                129 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                69 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X