Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

State.Realtime not working?

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

    State.Realtime not working?

    I'm trying to get some code to run every X number of bars while connected to the market.
    If I use this code it runs every bar.

    Code:
    protected override void OnBarUpdate()
    {
        if (CurrentBar % 10 == 0) ;
        {
            if (State == State.Realtime)
                {
                    Print("THIS IS PRINTING UNDER ON BAR UPDATE...");
                }
        }
    }

    If I use this code after 'else if (State == State.Configured)...
    Code:
    else if (State == State.Realtime)
    {
        if(CurrentBar % 10 == 0)
        {
            Print("THIS IS PRINTING UNDER STATE.REALTIME.");
        }
    }
    It runs only once during startup even though I'm not connected. While connected, it never runs.

    What am I missing?

    #2
    Hello hillborne,

    Thanks for your post.

    In your first code block, you have unintentionally terminated the If statement with a semicolon. If you remove that then your code should run every 10 bars on real-time data.

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Ahh...facepalm on the first block. Thanks!

      For the 2nd block, is it intended behavior? If I leave the test indicator on the chart and when starting up, that code will execute even though I'm not connected.

      Comment


        #4
        Hello hillborne,

        Thanks for your reply.

        No worries, we all do it.

        I would not expect State.Realtime to be true when not connected. I will investigate the 2nd code block and update this thread when I have further information.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello hillborne,

          After an internal review, it is expected that you would hit State.Realtime once in OnStateChange() only when it has finished initially loading (or reloading) historical data.

          We advise not to place code that references CurrentBar % 10 in OnStateChange as OnStateChange is not a data processing method and you would only see one print if that condition happens to be true.

          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Cross161, Today, 10:33 PM
          0 responses
          3 views
          0 likes
          Last Post Cross161  
          Started by neilzep, Today, 08:55 PM
          0 responses
          6 views
          0 likes
          Last Post neilzep
          by neilzep
           
          Started by javier.filgueira, Today, 03:29 PM
          3 responses
          10 views
          0 likes
          Last Post javier.filgueira  
          Started by Da vinci, Today, 03:15 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by Da vinci, Today, 02:51 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Working...
          X