• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Alert at certain time minus 5 minutes

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

    Alert at certain time minus 5 minutes

    Hi all. It's me. Again.

    I want to build a sound alert into my strategy that goes off 5 minutes before a chosen time (say a scheduled news release at 10:00 am).

    My first idea was this:
    if (Times[0][0].TimeOfDay > new TimeSpan(9, 54, 00) && Times[0][0].TimeOfDay < new TimeSpan(10, 00, 00))
    This way I would get a sound signal 5 times from 9:55 to 9:59. I like this, but in order to maintain it I need to type two times per alert. Not handy and error prone.

    My second idea was this:
    if (ToTime(Time[0]) >= NewsTime1Warning && ToTime(Time[0]) < NewsTime1))
    I would define NewsTime1 to be 100000 and NewsTime1Warning would be NewsTime1 minus 5 minutes.
    I like this better because I only have to type one time instead of two.

    Unfortunately, I cannot find an elegant solution here. While I would need to subtract 500 from say 93000 (to become 92500) I would need to subtract 4500 from 100000 (to become 95500). I can certainly write this in a long if statement, but it does not seem good coding and I am sure there is a function that does what I wish to do.

    Would anyone be so kind and give me a hint, please?

    P

    #2
    Hello pennywise,

    Thanks for your post.

    You could use the time span subtract method to subtract one timespan from another. For example, you can create a time span for your event and then create another timespan for your "warning" and then check to see of the bar close time is equal to the event time - the warning time. If you have several events you could use the same warning time span on each. Here is an example:



    Click image for larger version

Name:	Pennywise-1.PNG
Views:	22
Size:	104.1 KB
ID:	1060346


    There are probably better ways to do this and perhaps other community members will contribute to this as well.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you, PaulH, this is much better than what I had and works perfectly fine. Thank you.

      Just one question: Times[0][0].TimeOfDay accesses the time of my computer while ToTime(Time[0]) accesses the time of a bar within NinjaTrader, correct?

      Is my understanding correct? If yes, do you see an issue with using computer time? What if it happens to be off? Can NinjaTrader time be off?

      P

      Comment


        #4
        Hello pennywise,

        Thanks for your reply.

        The time series Time[0] and Times[0][0] are actually the same thing. In a single data series script, Time[0] is typically used as it points to the bar close time of the current bar of the primary data series. Times[0][0] is typically used in a multi-series script (and can be used in a single series script) when the first [] would point to the number of the data series and the second[] would point to the bar to reference.

        Both Time[0] and Times[0][0] are DateTime data types meaning they hold both a date and the time value (The date is the date of the bar and the time is the close time of the bar). Using Times[0][0] with the .TimeOfDay returns a timespan value that is just the time only without the date. (Time[0].TimeOfDay would also return the same thing)
        References:
        https://ninjatrader.com/support/help...eries_time.htm
        https://ninjatrader.com/support/help...ries_times.htm

        The ToTime() method returns an integer value representing time. Reference: https://ninjatrader.com/support/help...us/?totime.htm

        Here is an educational reference sample you may want to review/use for further understanding of date/time: https://ninjatrader.com/support/help...me_objects.htm

        DateTime and TimeSpan structures are C# and you can find further information on how to use them from various sites on the internet by searching for C# Date Time and or timeSpan. Here are a couple of links that may also be helpful:
        https://www.dotnetperls.com/datetime
        https://www.dotnetperls.com/timespan
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thank you, PaulH, fully clear now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by RobertoPaez, Today, 06:47 PM
          0 responses
          1 view
          0 likes
          Last Post RobertoPaez  
          Started by catinabag, Today, 06:45 PM
          0 responses
          1 view
          0 likes
          Last Post catinabag  
          Started by darkgreen, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post darkgreen  
          Started by GTBrooks, Today, 02:44 PM
          3 responses
          14 views
          0 likes
          Last Post GTBrooks  
          Started by GLFX005, Today, 12:22 PM
          4 responses
          41 views
          0 likes
          Last Post NinjaTrader_Kate  
          Working...
          X