Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

audio alert upon completion of a bar

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

    audio alert upon completion of a bar

    I've tried to find/understand how to get an
    audio file to play when a bar is complete, or
    better yet, a few seconds before. If a chart
    is using 2 minute bars I would like an alert
    when a bar is about done (110 seconds). I've tried to get
    market analyzer to do it but have given up
    for now.

    Is there a way? I've tried Columns, then Last Close,
    but I'm not sure what I'm doing.

    - Stephen

    #2
    I guess PercentComplete might work?
    I'll try that unless I get a comment.

    Comment


      #3
      Ok, I'm heading out now. I did get an alert to sound
      upon the completion of a bar.

      {
      if(Bars.PercentComplete>0)


      {

      PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");
      }

      I've tried to get the alert to sound a few seconds earlier but
      all the values that I replace '0' with don't help.

      Any suggestions?

      Thanks,

      - Stephen

      Comment


        #4
        Originally posted by stephenszpak View Post
        Ok, I'm heading out now. I did get an alert to sound
        upon the completion of a bar.

        {
        if(Bars.PercentComplete>0)


        {

        PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");
        }

        I've tried to get the alert to sound a few seconds earlier but
        all the values that I replace '0' with don't help.

        Any suggestions?

        Thanks,

        - Stephen
        Make sure you have Calculate on bar close set to false

        Comment


          #5
          Thanks, I don't think I would have figured this
          out. It helps, but the alert keeps playing until
          the end of the bar. I tried BREAK and using
          a < and >, FOR, and one or two other things.
          but it won't generate because of some
          error in how I'm doing it.
          Spent about 45 minutes.

          {
          if (Bars.PercentComplete>.91666)
          {

          PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\110 seconds.wav");





          }




          }

          Comment


            #6
            There is also another problem. I have converted a text file to audio
            to play "110 seconds, 110 seconds". But it plays" 100 100 100 110
            seconds 110 seconds".

            If I substitute the Alert1 sound that comes with NT, it plays 4 times
            within my script. But it plays just once in WinAmp.

            I think there is a connection with the two situations here.

            It seems the sound that is played is automatically repeated a number
            of times when using PlaySound(@''C:\Program Files\NinjaTrader 6.5\sounds
            which is not useful in what I'm going for here.

            - Stephen

            Comment


              #7
              Originally posted by stephenszpak View Post
              if (Bars.PercentComplete>.91666)
              This will be "true" more than one time.

              Set a flag, like:

              bool playedaudio = false;

              then once you play it (after PlaySound) set to true:
              playedaudio = true;

              be sure to reset it on the next bar:

              if (FirstTickOfBar)
              playedaudio = false;

              Mike

              Comment


                #8
                I tried what you said, (probably incorrectly) it doesn't work.

                I altered the WAV file to play "110 seconds, 110 seconds"
                to which I added thirty seconds of silence. It plays correctly
                in WinAmp.

                So in NT it's NOT like it's repeating until the end of the bar.
                It's almost stuttering. It's saying 100, like five or six times,
                then 110 seconds, 110 seconds. The longer the duration of the bar
                the greater the number of times it says '100'. So it is repeating, but
                not repeating the entire audio file. Even if it played just once I think
                it would not play correctly.

                Comment


                  #9
                  Are you reproducing this using market replay? What speed, if so?

                  I use audio alerts as well, and in a market replay session they will get cut off and trampled on due to the replay speed.

                  Having 30 seconds of white space at the end is not going to accomplish anything in my opinion, NT will just cut off the audio file in the middle of playing if it wants to play another one. It doesn't wait for the file to finish playing.

                  Mike

                  Comment


                    #10
                    Just using simulated data at normal speed.
                    120 second bars, or less so I don't have to wait too long.

                    Comment


                      #11
                      Throw in a couple of Print statements so we can see what is happening. Remember to open the Output Window.

                      Print(Time[0] + ": blah blah" + ", % complete = " + Bars.PercentComplete.ToString() + ", Close[0] = " + Close[0]);

                      change the blah blah to something useful like "before audio" and "after audio" etc.

                      Then run it again and see what is happening, notice the time stamps.

                      Mike

                      Comment


                        #12
                        Also,

                        Going back to the boolean for playedaudio.

                        On your PlaySound() line, it needs to be:

                        if (!playedaudio)
                        PlaySound()

                        Mike

                        Comment


                          #13
                          #variables
                          bool playedaudio = false;

                          #onbarupdate
                          if (FirstTickOfBar)
                          {

                          Print(Time[0] + ": I am resetting playedaudio to false, % complete = " + Bars.PercentComplete.ToString() + ", Close[0] = " + Close[0]);

                          playedaudio = false;

                          }

                          if (Bars.PercentComplete>.91666 && !playedaudio)
                          {

                          Print(Time[0] + ": I'm about to play some sound, % complete = " + Bars.PercentComplete.ToString() + ", Close[0] = " + Close[0]);

                          PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\110 seconds.wav");

                          playedaudio = true;

                          }

                          Mike

                          Comment


                            #14
                            Thanks. I'll try for an hour or so.

                            Comment


                              #15
                              I got this and I lost it, and I got it, so I'm posting it now.
                              The program below plays "110 seconds, 110 seconds"
                              The problem should be quite simple now. It ONLY does this
                              for the first bar. The stuttering is gone, which was very important.

                              --------------------------------------------------------------

                              The...

                              #onbarupdate
                              if (FirstTickOfBar)


                              ...which was suggested, was not done correctly on my part.
                              There was an error I couldn't get rid of so it's not part of the programming below.
                              -------------------------------------------------------------------------

                              If this line is NOT in the program below, there is stuttering:

                              playedaudio = true;

                              -------------------------------------------------------------------------------

                              #region Variables

                              bool playedaudio = false;


                              // Wizard generated variables
                              private int myInput0 = 1; // Default setting for MyInput0
                              // User defined variables (add any user defined variables below)
                              #endregion

                              protected override void OnBarUpdate()


                              {


                              if (Bars.PercentComplete>.91666 && !playedaudio)
                              {



                              PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\110 seconds 110 seconds.wav.");


                              playedaudio = true;

                              }
                              }
                              Last edited by stephenszpak; 05-10-2009, 01:06 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,413 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X