Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X