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

Using Tick chart bar time to trigger sound alert

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

    Using Tick chart bar time to trigger sound alert

    Hello,
    I want to trigger an audible alert x minutes before a time.... such as NY cash Open/Close, DAX cash Open/Close, Gold/CL etc.
    Context - I'm in Europe so have to contend with DST (hats off to Harry for his expertise in cracking this one)

    I believe I have a problem relating to Tick bars and time stamp if using Time[0] - either the time stamp of a tick bar may not equal the Open/Close precisely, or maybe, not at all.

    This is what I've got:
    using OnBarUpdate, and CalculateOnBarClose = False....
    if(Time[0] == newyorkStartTimeLocal.AddMinutes(-15))
    {
    PlaySound(newyorkOpenAlert);
    }
    where newyorkOpenAlert is a texttospeech .wav file 'New York Opening in 15 minutes'
    Ditto for Dax etc.
    'Local' sets to relevant Time Zone

    It seems it works sometimes.
    If that is so, is it something to do with the tick bar timestamp?
    If so, what is it? I was wondering if to do with Seconds? NTYStartTimeLocal is hh:mm:ss and to be == Time[0] tick bar's time stamp also have to be :00 seconds (unlikely)
    What to do?
    I'm not a programmer - so near yet so far.
    I believe I can't use ToTime with ==, has to be <=, so no good for a fixed Open time
    I believe I could use DateTimeNow to use my pc clock, but not sure of DST implications
    The only time-based charts I use are 30 and 60 mins so that doesn't give me 'granularity' for 15 or 5 mins warning alerts.
    Any ideas?
    TIA

    #2
    Hello brucerobinson,

    Yes, this could have to do with the time of the tick bar. For example if there was not a trade at exactly the newyorkStartTimeLocal minus 15, then the condition would not be true.

    To demonstrate this point I have put together a sample strategy which buys long if the time equals 930. You’ll notice the left chart has historical trades while the right does not. This is due to the left chart being a 30MIN chart and having a bar that closes at 930, whereas the right chart, a 40 minute chart, has a bar close at 9:20 and another at 10:00, thus time never equals 9:30.

    What you could do is use a time filter and ask if the current time was between say 930 and 931, assuming you will have a tick/trade within a minute. Then you could have the alarm set to rearm after 90 seconds, so that it would only go off 1 time.

    The code might look something like this,

    Code:
    if(ToTime(Time[0]) >= 93000 || ToTime(Time[0]) <= 93100)
    {
    Alert(@"MyCustomStrategy6_1", Priority.Medium, @"This alert", @"C:\Program Files (x86)\NinjaTrader 8\sounds\Alert4.wav", 90, Brushes.Transparent, Brushes.Yellow);
    }
    Please let us know if you need further assistance.
    Attached Files
    Last edited by NinjaTrader_AlanP; 05-05-2017, 02:40 PM.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello Alan,
      Many thanks for confirming and explaining so completely - I appreciate that, especially not being experienced coding (well, I did some Fortran 40 years ago :-().
      It looks straightforward enough, almost cut and paste. I'm not well-versed in Alert so will check out the 'brushes' bit for my education.
      I guess the 'logic' is:-
      I need to eliminate the == exact time-match requirement and use a time period filter to achieve this.
      Consequently, I need to use a rearm function, to ensure the alarm is not repeated by every tick in the period. The rearm period needs to extend until after the time filter period i.e. greater than.

      For my education - is there a reason for using/preference for rearm over onbarupdate && firsttickofbar?

      Hopefully won't be back, unless I can't get it to work!
      Best

      Comment


        #4
        not quite.....

        Hello Alan,
        this doesn't appear to solve my DST handling requirement.
        If I try to apply the approach you suggest as follows:....

        if(ToTime(Time[0]) >= daxStartTimeLocal.AddMinutes(-15) || ToTime(Time[0]) <= daxStartTimeLocal.AddMinutes(-14))
        {
        Alert(@"DAX Opens in 15 minutes", Priority.Medium, @"daxOpenAlert", @"C:\Program Files (x86)\NinjaTrader 7\sounds\DAXOpen15mins.wav", 90, Brushes.Transparent, Brush1);
        }

        .... it seems to object to using daxStartTimeLocal.AddMinutes(-xx) instead of an absolute value such as 93000

        And that takes me back in a circle to the initial stipulation of a solution that addresses Time Zone handling for Daylight Savings Time with instruments on Exchanges in different time zones

        Time Zones/DST is sorted, tick bars gives me a time stamp problem to trigger an alert, proposed solution addresses that if using a time value, but seems not compatible with a string

        Any further suggestions.....
        Thanks

        Comment


          #5
          Hello brucerobinson,

          You should convert your DateTime object into an integer.

          Code:
          if(ToTime(Time[0]) >= ToTime(daxStartTimeLocal.AddMinutes(-15))
          Please let us know if you need further assistance.
          Alan P.NinjaTrader Customer Service

          Comment


            #6
            Ah.
            Easy when you know how.
            Many thanks
            Bruce

            Comment


              #7
              was suspicious of that brushes business from the outset....
              Compiling error - 'The name 'Brush1' does not exist in the current context'?
              Thanks
              Bruce

              Comment


                #8
                Hello brucerobinson,

                Please see the sample alert in the following section of our helpguide.


                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  I'd already looked at that before getting back to you. Well actually when I saw it in the snip of code you initially gave me using Alert instead of Playsound I was initially using.
                  You have Brush1 in the code you provided, which does not follow the syntax in the Help file you now refer me to which I'd already looked at.
                  I've already pointed out I've no desire for the alert in the Alert window function.
                  However, if it is required - simple question: will Brushes.Transparent work for the foreBrush color. It seems it follows the standard syntax given in the Help example, which the sample you gave me does not and seems to be the cause of the futher problems I am now having to address.
                  thanks
                  Last edited by brucerobinson; 05-05-2017, 03:11 PM.

                  Comment


                    #10
                    no it doesn't
                    tried Brushes.Yellow which is what is in the Help example, comes back with all sorts of C1502 and C1503 errors, for something I don't actually want to do....
                    To let you know I need further assistance.....

                    Comment


                      #11
                      this is the code:
                      please assist in identifying what is wrong.
                      In the first instance I used the code with Brushes1 you gave me which produced errors.
                      Now I have used the syntax per the Help file you referred me to, correctly as far as I can see.

                      if(ToTime(Time[0]) >= ToTime(londonStartTimeLocal.AddMinutes(-15)) || ToTime(Time[0]) <= ToTime(londonStartTimeLocal.AddMinutes(-14)))
                      {
                      Alert(@"DAX Opens in 15 minutes", Priority.Medium, @"daxOpenAlert", @"C:\Program Files (x86)\NinjaTrader 7\sounds\DAXOpen15mins.wav", 90, Brushes.Transparent, Brushes.Yellow);
                      }

                      Comment


                        #12
                        Hello brucerobinson,

                        The link/example I provided was for NT8, my apologies.

                        If you swap

                        Code:
                        Brushes.Transparent, Brushes.Yellow
                        for

                        Code:
                        Color.Black, Color.Yellow
                        like the example in the NT7 helpguide, do you no longer receive errors?


                        I look forward to your reply.
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Alan,
                          Yes, I figured that out over the weekend - well, not that yours was NT8, rather that the Ninja Help example for 7 was not as you had provided so changed it per Help and it compiled.

                          Also, isn't the use of || incorrect here? || being 'or else'.
                          The condition I want to be true is that the time onbarupdate is greater than or equal to 15minutes before the session open time 'and also' less than or equal to 14minutes before the session open i.e. during that one minute starting 15minutes before the open (and won't rearm until the condition is no longer true, 90 seconds after it is triggered by which time the second condition <= -14 cannot be true because current time on the next bar update must be 'past' i.e. greater than -14 before open.
                          I tried the code with || and it alerted all alerts every 90 seconds, which would be expected as with || is always true (maybe not during the -15 to -14 period, haven't thought it through)
                          Thanks

                          In which case I should be using '&&' not '||'

                          Comment


                            #14
                            Hello brucerobinson,

                            Yes, the and operator "&&" sounds to be the correct operator in this case.

                            Please let us know if you need further assistance.
                            Alan P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by frankthearm, Today, 09:08 AM
                            5 responses
                            14 views
                            0 likes
                            Last Post NinjaTrader_Clayton  
                            Started by jeronymite, 04-12-2024, 04:26 PM
                            3 responses
                            43 views
                            0 likes
                            Last Post jeronymite  
                            Started by yertle, Today, 08:38 AM
                            5 responses
                            16 views
                            0 likes
                            Last Post NinjaTrader_BrandonH  
                            Started by adeelshahzad, Today, 03:54 AM
                            3 responses
                            19 views
                            0 likes
                            Last Post NinjaTrader_BrandonH  
                            Started by bill2023, Yesterday, 08:51 AM
                            6 responses
                            27 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Working...
                            X