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

play sound 2x's

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

    play sound 2x's

    I have the following signal that plays a sound when true

    if(mySignal[0] == 1.0)
    {
    DrawDot(
    "MyDotbuy"+CurrentBar, true, 0, Low[0] - (2 * TickSize), Color.Blue);
    PlaySound("Alert1.wav");
    }

    How do I get the sound to play only 2x's when it is true. Currently it beeps every time when the bar is updating.

    Can anyone show me an example?

    Thanks

    #2
    Hello,

    Try something like this:


    if(mySignal[0] == 1.0 && cnt < 2)
    {
    DrawDot(
    "MyDotbuy"+CurrentBar, true, 0, Low[0] - (2 * TickSize), Color.Blue);
    PlaySound(
    "Alert1.wav");
    cnt++;
    }

    //you will need to put int cnt = 0; somewhere, where you want to
    //allow the signal to reset and allow it to go off again.
    DenNinjaTrader Customer Service

    Comment


      #3
      thanks, I will give it a try

      Comment


        #4
        Hi Ben,

        I tried your script and could not get it to work, the sound continued to play repeatedly. I tried the following:

        protectedoverridevoid OnBarUpdate()
        if (condition)

        {
        for (int x = 0; x < 2; x++)
        {
        PlaySound("Alert1.wav");
        }

        }

        any thoughts?
        Last edited by velocity; 02-01-2010, 06:25 AM.

        Comment


          #5
          velocity,

          Your variant will not work. You should try what Ben suggested with a counter variable instead of a loop. Your loop is reset every time your trade condition is true. Your counter should be a part of the condition at the very beginning.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            I have tried many many different variations to try and make this work and the counter just does not add when I look in the output window. the number is always #1.


            protectedoverridevoid OnBarUpdate()

            int count = 0;

            if(mySignal[0] == 1.0)
            {
            DrawDot("MyDotbuy"+CurrentBar, true, 0, Low[0] - (2
            * TickSize), Color.Blue);
            count++;


            if(count < 2) {PlaySound("Alert1.wav");}

            Print(Time[0].ToLongTimeString() + " " + count.ToString());

            }


            The condition may be true 500+ times when the bar is forming. The output window just prints rapid #1's as the bar is updating instead of counting 1,2,3,4, etc. As a result the beeps are in rapid fire play mode. I only want one beep per bar.

            Where am I going wrong?

            Comment


              #7
              int i = 2
              while (i > 0)
              {
              PlaySound("Alert1.wav");
              i--;
              }

              Comment


                #8
                I am a little lost on your post.

                Are you saying:


                protectedoverridevoid OnBarUpdate()

                if(mySignal[0] == 1.0)
                {
                DrawDot("MyDotbuy"+CurrentBar, true, 0, Low[0] - (2
                * TickSize), Color.Blue);

                int i = 2;
                while (i > 0);
                {
                PlaySound("Alert1.wav");
                i--;
                }


                Print(Time[0].ToLongTimeString() + " " + i.ToString());

                }

                Comment


                  #9
                  ya, and since you dont want it on historical do add

                  if (Historical)
                  {
                  // dont play sound

                  }

                  again you can simply make a copy of the the wav file and call it twice

                  if (condition)
                  {
                  PlaySound("Alert1.wav");
                  PlaySound("Copy of Alert1.wav");
                  }

                  Comment


                    #10
                    Sorry, I can't follow what you are doing there. I have way too many conditions to add that kind of coding to my indicator.

                    Thanks for taking a look.

                    Anyone else have an Idea?

                    Comment


                      #11
                      velocity, which exact code are you know using? Wouldn't this work for you below as suggested in this thread?

                      Code:
                       
                      protected override void OnBarUpdate()
                      {
                      if (Close[0] > Open[0])
                      
                      { 
                      alertCalls = 2;
                      while (alertCalls > 0)
                      {
                      PlaySound("Alert2.wav");
                      alertCalls--;
                      }
                      }
                      Plot0.Set(Close[0]);
                      }
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        I don't get it. Your code continually beeps when close is above open. I want to do just the opposite. I only want the beep to sound off 2x as long as price is above open on the Current Bar. If it falls back below the open it resets and then if price rises above open again on "the Current Bar", it will beep 2x's and then stop.

                        The way you have it written, as long as price is above open, it beeps.

                        Any thoughts on how to accomplish this would sure be appreciated.

                        thanks

                        this is what I have as an example:

                        #region Variables
                        // Wizard generated variables
                        privateint myInput0 = 1; // Default setting for MyInput0
                        int alertCalls = 0;

                        #endregion

                        protectedoverridevoid Initialize()
                        {
                        Add(
                        new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                        CalculateOnBarClose =
                        false;
                        Overlay =
                        false;
                        }

                        protectedoverridevoid OnBarUpdate()
                        {

                        if (Close[0] > Open[0])
                        {
                        alertCalls =
                        2;
                        while (alertCalls > 0)
                        {
                        PlaySound(
                        "Alert2.wav");
                        alertCalls--;
                        }
                        }
                        Print(Time[
                        0].ToLongTimeString() + " " + alertCalls.ToString());
                        Plot0.Set(Close[
                        0]);
                        }
                        Last edited by velocity; 02-02-2010, 10:23 AM.

                        Comment


                          #13
                          Use a bool?

                          #region Variables
                          // Wizard generated variables
                          privateint myInput0 = 1; // Default setting for MyInput0
                          int alertCalls = 0;
                          bool CloseAboveOpen = false;

                          #endregion

                          protectedoverridevoid Initialize()
                          {
                          Add(
                          new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                          CalculateOnBarClose =
                          false;
                          Overlay =
                          false;
                          }

                          protectedoverridevoid OnBarUpdate()
                          {

                          if (Close[0] > Open[0])
                          {
                          if(!CloseAboveOpen)
                          {

                          alertCalls =
                          2;
                          while (alertCalls > 0)
                          {
                          PlaySound(
                          "Alert2.wav");
                          alertCalls--;
                          }
                          CloseAboveOpen = true;
                          }
                          }
                          Print(Time[
                          0].ToLongTimeString() + " " + alertCalls.ToString());
                          Plot0.Set(Close[
                          0]);
                          }

                          if(Close[0] < Open[0])
                          CloseAboveOpen = false;


                          Not tested. Dan
                          eDanny
                          NinjaTrader Ecosystem Vendor - Integrity Traders

                          Comment


                            #14
                            In addition to eDanny's idea/code, you could also simply combine the single beep into a double beep with some sound editing program and then you wouldn't have to worry about triggering it twice. That would greatly simplify the rest of the process.
                            AustinNinjaTrader Customer Service

                            Comment


                              #15
                              Austin has the best idea.

                              All of these options with loops and such will probably have the sound file play twice, but the sounds may overlap depending on the length of time they require to play. Best bet is to just modify the sound file itself to loop.
                              mrlogik
                              NinjaTrader Ecosystem Vendor - Purelogik Trading

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bmartz, 03-12-2024, 06:12 AM
                              4 responses
                              31 views
                              0 likes
                              Last Post bmartz
                              by bmartz
                               
                              Started by Aviram Y, Today, 05:29 AM
                              4 responses
                              11 views
                              0 likes
                              Last Post Aviram Y  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              3 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by gentlebenthebear, Today, 01:30 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by cls71, Today, 04:45 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X