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.

    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.

        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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          597 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          555 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X