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 alifarahani, Today, 09:40 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by RookieTrader, Today, 09:37 AM
          4 responses
          17 views
          0 likes
          Last Post RookieTrader  
          Started by PaulMohn, Today, 12:36 PM
          0 responses
          4 views
          0 likes
          Last Post PaulMohn  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          39 views
          0 likes
          Last Post love2code2trade  
          Started by junkone, Today, 11:37 AM
          3 responses
          23 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X