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

Looking for a time alert indicator

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

    Looking for a time alert indicator

    Hi,

    Looking for an indicator which allows the setting of an alarm daily based on time. So, for instance I can chose a audible alert to go off at 11:30 each day to tell me London is closing...

    Yes, yes. I know I can just use a clock. LOL. Anyone know of an indicator which I can use in Ninja to alert me audibly at certain times every day ? Looked in the ninjascript file sharing, couldn´t find anything.

    Thanks.

    #2
    Hello ScottieDog,

    Thank you for your post.

    This can be done working with ToTime in NinjaScript. For example, if you wanted to play a sound at a bar timestamped at 11:30 you could do something like this:

    Code:
    if( ToTime(Time[0]) == 113000 )
    {
        PlaySound(@"C:\alarmsound.wav");
    }
    For more information on working with times and dates please see the following example:


    Also, this indicator may do what you need, it appears to have an alert functionality:

    Last edited by NinjaTrader_Dexter; 04-21-2011, 04:55 PM.
    DexterNinjaTrader Customer Service

    Comment


      #3
      OK. Well, I have done a new NinjaScript which is attached below... I compiled it and then added the indicator to the chart..... Seems OK....

      How can I add a few options inside the indicator preference ? So I can change the notification time, and the notification sound from inside the preferences, rather than editing the code each time ? What code do I add to the script ?

      Can anyone help with that ? Thanks.





      namespace NinjaTrader.Indicator
      {
      /// <summary>
      /// Audible alert when reaching a specific point of the day
      /// </summary>
      [Description("Audible alert when reaching a specific point of the day")]
      public class AlertTime : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      if( ToTime(Time[0]) == 113000 )

      PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\2minsLondonclose.wav");
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.
      Plot0.Set(Close[0]);
      }

      #region Properties
      [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
      [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
      public DataSeries Plot0
      {
      get { return Values[0]; }
      }

      [Description("")]
      [GridCategory("Parameters")]
      public int MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(1, value); }
      }
      #endregion
      Last edited by ScottieDog; 04-22-2011, 05:39 AM.

      Comment


        #4
        Hello,

        Please see this sample on how to create user defined input parameters.



        Let me know if you have any questions.

        Comment


          #5
          Say if I want an alert to go off at every 9 minute mark of the hour, eg 3:09, 4:09 etc. How would I do this? Am also interested in minutes and seconds. eg 3:08:30, 4:08:30 etc.

          Thanks, Stephen

          Comment


            #6
            Hello Slide588,

            If you would like to do this, you would want to check the current time against the current bar's time to see if the value is at 9 minutes.

            Here is a short code sample of how you could achieve this:
            Code:
            if(Time[0].Minutes == 9)
            Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
            If you would also want to incorporate seconds into your check, you can add the following logic:
            Code:
            if(Time[0].Minutes == 9 && Time[0].Seconds == 30)
            Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
            You can find more information on the Time object here:
            http://ninjatrader.com/support/helpGuides/nt7/time.htm

            You can find more information on the Alert() method here:
            http://ninjatrader.com/support/helpGuides/nt7/alert.htm

            Please let me know if I may be of any further assistance.
            Alan S.NinjaTrader Customer Service

            Comment


              #7
              Hi

              I'm interested in firstly determining the time per bar automatically, so say 3 minute or 5 minute OHLC bars then having an Alert fire when the bar is 15 seconds from closing.

              Got the Alert firing for certain times as below, now want to generalize this.

              Thanks!

              Comment


                #8
                Hello Slide588,

                Thanks for your post.

                You can refer to the documentation time for more information on how to check the time of a bar:
                http://ninjatrader.com/support/helpGuides/nt7/time.htm

                Then you would need to create a time check to check if the bar is 15 seconds from closing. One way you could do this is to use the ToTime() method to check the current bar's closing time against the current time, then check if there are 15 seconds remaining on the current bar from the difference between the two time values.

                For example, imagine we are running this script on a 3 minute bar object. This first check subtracts the current time by the previous bar's time. Checking the time stamp of a minute bar object will always return the time of the close of that bar. This is different than a Tick-based bar type, which will return the time stamp of the last recorded tick when we attempt to retrieve it. If there are 15 seconds left on the current bar, the difference between the closing time of the current bar and the current time will be 15 after ToTime() converts the DateTime values to integer values.
                Code:
                if(ToTime(Time[0]) - ToTime(DateTime.Now) == 15)
                Alert("myAlert", NinjaTrader.Cbi.Priority.High, "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
                Note that when you want to detect intra-bar events, you will need to set the CalculateOnBarClose property to false, so that your logic runs on each incoming tick rather than just once at the close of the bar. With this in mind, also consider that a tick will have to be received within the last 15 seconds of the bar in order for this logic to be ran and for your alert to trigger.

                You can find more information about ToTime() and CalculateOnBarClose in our help guide here:
                ToTime() - http://ninjatrader.com/support/helpG...nt7/totime.htm
                CalculateOnBarClose - http://ninjatrader.com/support/helpG...onbarclose.htm

                Please let me know if I may be of any further assistance.
                Alan S.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Alan,

                  I looked up ToTime and this returns an integer value in HMMSS. So the suggested solution won't work as desired. eg 15 seconds to 12:03 would be 120300-120245. I could parse the returned integers to convert to seconds then subtract but is there an easier way?

                  Along the same lines, how can I tell how long a bar lasts for. ie for a 3 min bar I want 3 returned, 5 min bar 5 returned.

                  Thanks

                  Comment


                    #10
                    Hello Slide588,

                    Thanks for your reply.

                    Are you able to see the code sample I provided in my previous post? I provided an example of how you would use the ToTime() method to check if there was 15 seconds left on the bar:

                    if(ToTime(Time[0]) - ToTime(DateTime.Now) == 15)

                    There is no need to parse the returned integers to convert to seconds. The purpose of the ToTime() function is to return DateTime objects in an integer format to make them easier to work with, such as the case here where we want to implement bar time checks.

                    You can use BarsInProgress to check which series OnBarUpdate() is being called by, then check the BarsPeriod.Value to retrieve the period value.

                    You can find more information on BarsInProgress and BarsPeriod.Value in our help guide here:

                    BarsInProgress - http://ninjatrader.com/support/helpG...inprogress.htm

                    BarsPeriod - http://ninjatrader.com/support/helpG...barsperiod.htm

                    Please let me know if I may be of any further assistance.
                    Alan S.NinjaTrader Customer Service

                    Comment


                      #11
                      > Are you able to see the code sample I provided in my previous post? I provided an
                      > example of how you would use the ToTime() method to check if there was 15 seconds > left on the bar:

                      > if(ToTime(Time[0]) - ToTime(DateTime.Now) == 15)

                      Hi Alan, yes I can see it and coded it and it doesn't work which is what I was pointing out.

                      eg for a 12:03 bar:

                      ToTime(Time[0] = 120300

                      15 seconds beforehand is:

                      ToTime(DateTime.Now) = 120245.

                      120300-120245 = 55.

                      See what I mean? Thanks

                      Comment


                        #12
                        Hello Slide588,

                        Thanks for pointing that out - in this particular case we can amend the value in the check to 55 to represent being 15 seconds away from the close of the bar.

                        Please let me know if I may be of any further assistance.
                        Alan S.NinjaTrader Customer Service

                        Comment


                          #13
                          Unfortunately not Alan.

                          For the 12:00 bar we have:

                          ToTime(Time[0] = 120000

                          15 seconds beforehand is:

                          ToTime(DateTime.Now) = 115945

                          120000-115945 = ...

                          I'd actually like the alert to sound once at 15 seconds or less. Like I say, I can parse the values but would be surprised if there's not a call that does this. Could you please investigate.

                          Thanks

                          Comment


                            #14
                            Hello Slide588,

                            To avoid this difficulty, we should create a check only looking at the minute seconds values:

                            if(DateTime.Now.Minute == (Time[0].Minute - 1) && (60 - DateTime.Now.Seconds) <= 15)

                            Please let me know if I may be of any further assistance.
                            Alan S.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks Alan, we'll still have trouble on the hour as 0 minutes - 1 is negative so have to check for that case. But I've got the idea. Cheers.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,234 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,414 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Yesterday, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Working...
                              X