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

Loop for time in Seconds

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

    Loop for time in Seconds

    Is there a way to do a loop and update a parameter every few seconds?

    I've looked on the forum and can't find anything like this.

    I'm guessing:

    if (Time[0] + 10 seconds)

    {
    Do Something
    }
    I've taken a shot at it, but can't find the right syntax.

    TIA...

    taddypole...

    #2
    Originally posted by Taddypole View Post
    Is there a way to do a loop and update a parameter every few seconds?

    I've looked on the forum and can't find anything like this.

    I'm guessing:

    if (Time[0] + 10 seconds)

    {
    Do Something
    }
    I've taken a shot at it, but can't find the right syntax.

    TIA...

    taddypole...
    That will depend on what kind of chart period you are using.

    Comment


      #3
      Haven't tried it but i think you can do this with the timer class

      search for C# timer in Google
      Monitor processes with the Timer class from the System.Timers namespace.


      Questions is where to put it into the NinjaTrader code

      Comment


        #4
        I'm using LineBreak tick charts with various settings, and want to create a timer that would cycle somewhere between 20 to 50 seconds. The goal is to determine how long it takes to form a bar.

        Comment


          #5
          Taddypole,

          If you use COBC = false, then you can keep track of the time between "FirstTickOfBar" from one bar to the next using Time[0].

          Something like this :

          If ( FirstTickOfBar )
          {
          Time = PreviousFirstTickTime - Time[0];
          }

          Here is a link to the help guide : http://www.ninjatrader.com/support/h...ttickofbar.htm

          Please let me know if I may assist further.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by Taddypole View Post
            I'm using LineBreak tick charts with various settings, and want to create a timer that would cycle somewhere between 20 to 50 seconds. The goal is to determine how long it takes to form a bar.
            The time it takes to form a bar is simply (Time[0] - Time[1]) taken from FirstTickOfBar if COBC = false, otherwise, as is.

            Is there a deeper purpose that I am missing?

            Comment


              #7
              I'm making progress, but now stumped on an error message from the code below.
              And note, the code is not functional as is, but I need to get by this error message in order to complete the logic.

              "Error Message" (While pointing at the Time[0] term)

              Cannot implicitly convert type 'System.TimeSpan' to 'System.DateTime'

              When I use either of the lines:

              ElapsedTime = Time[0] - TimeRef;
              or
              // ElapsedTime = Time[0] - Time[1];

              I get the same error message.

              any ideas?

              And my goal is to have intrabar updates, not after the bar has completed. That's the reason for the timer. Some bars complete in a few seconds, but others take five minutes. I want to know when a bar is taking excessively long to complete.

              Thanks, taddypole...


              Here's the code:

              #region Variables

              private DateTime TimeRef;
              private DateTime ElapsedTime;

              protected override void OnBarUpdate()

              if (FirstTickOfBar)
              {
              TimeRef = Time[0];

              }
              int result = (DateTime.Compare(now, TimeRef));
              if (result == 0)
              {
              TimeRef = Time[0];
              ElapsedTime = Time[0] - TimeRef;
              // ElapsedTime = Time[0] - Time[1];
              }
              Last edited by Taddypole; 01-08-2012, 02:55 PM.

              Comment


                #8
                Taddypole,

                It would be easier to test if you would post your .cs file here. That way we can compile it ourselves and test.

                For debugging, I suggest liberal use of print statements and try/catch blocks.

                This line here: Time[0] - TimeRef

                Is an arithmetic operation, as such you cannot apply it to DateTime objects. Here is probably what you want to use : http://msdn.microsoft.com/en-us/library/8ysw4sby.aspx

                Please let me know if I may assist further.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  In your code as written, ElapsedTime is a TimeSpan variable, not a DateTime variable. You want to declare it correctly.

                  Until we get used to it, the compiler's error messages can be a bit cryptic, but this one does say it pretty much plainly.

                  Regardless, the time passed in a bar is still Time[1] - Time [0]. If you are using a period type other than fixed minutes, then this will give you the elapsed time: intrabar if you are using COBC = false, otherwise the total time passed to completion of the bar.
                  Last edited by koganam; 01-08-2012, 03:45 PM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, 04-17-2024, 06:40 PM
                  6 responses
                  48 views
                  0 likes
                  Last Post algospoke  
                  Started by arvidvanstaey, Today, 02:19 PM
                  4 responses
                  11 views
                  0 likes
                  Last Post arvidvanstaey  
                  Started by samish18, 04-17-2024, 08:57 AM
                  16 responses
                  61 views
                  0 likes
                  Last Post samish18  
                  Started by jordanq2, Today, 03:10 PM
                  2 responses
                  9 views
                  0 likes
                  Last Post jordanq2  
                  Started by traderqz, Today, 12:06 AM
                  10 responses
                  19 views
                  0 likes
                  Last Post traderqz  
                  Working...
                  X