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

PlaySound () triggers in indicator but plays ad infinitum

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

    PlaySound () triggers in indicator but plays ad infinitum

    if (bands && CurrentBar > Period + 20)
    {
    if ( (Close[1] > Upper[1])
    && (Close[2] > Upper[2])
    && (Close[3] < Upper[3])
    && (Close[4] < Upper[4]) )

    {
    if (PlotVert)
    {
    Draw.VerticalLine(this, @"bands long" + CurrentBar, 2, Brushes.Lime, DashStyleHelper.Dash, 1);
    }

    if (bandsignalsound && ( (Close[1] > Upper[1]) && (Close[2] > Upper[2]) && (Close[3] < Upper[3]) && (Close[4] < Upper[4]) ))
    {
    PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\glassbreaking.wav");
    }

    just plays endlessly - till i toggle off bandsignalsound and reload ninjascript on that chart.... yoiks!!

    - i repeated the conditions for the signal with the toggle to see if that would help cause i though it would make it last for only one bar - but that didn't help...
    Last edited by stafe; 01-22-2020, 02:29 PM.

    #2
    Hello stafe,

    Thanks for your post.

    Could you clarify on the following?

    When adding prints next to PlaySound, do you see multiple prints fire in the output window when this is occuring? This would point to a logical issue where the logic is reaching PlaySound multiple times.

    Do you see this behavior when testing with a different sound file like Alert2.wav? This would point to an issue with the formatting of the wav file. (16bit PCM wav files are used in NinjaTrader.)

    Does this occur when testing PlaySound with that wav file in a new script that simply calls PlaySound in OnBarUpdate when the strategy is set to Calculate.OnBarClose? How about with Alert2.wav? This would point to larger installation issues.

    I look forward to your reply.
    JimNinjaTrader Customer Service

    Comment


      #3
      indicator runs in Calculate.OnPriceChange so i made the signal rules specific to bar Close[1]-[4] attributes relative to an indicator plot Upper[1]-[4] and Lower[1]-[4] in hopes of preventing something like this from happening...

      behavior running simulated data is the same with NT's Alert*.wav files that are 1536kbps vs my glassbreaking.wave file which is 88kbps in the same directory...
      however using simulated data the sound file is only called on each price update event during bar[0] so for sure it seems like the call is going out more than once...

      there are no prints in the NinjaScript Output window for any event involving this indicator so is there any way to know if the indicator is repeatedly painting the signal price levels and vertical lines as well ?
      the draw commands do have a bar specific identifier in their tag - does that prevent future re-draws ?

      i'm thinking i need a way to opt out of playing the sound again if that line of code has already run on this particular bar but my skill level doesn't immediately cut it... probably need to cover all the signal elements as well - the horizontal lines and the vertical line if selected...
      thanks,
      w

      Comment


        #4
        should i put all the "signal" elements - the lines and sound in an if (isFirstTickofBar) section ?

        Comment


          #5
          sorry 'bout the extra replies... i did get things to behave with simulated data when i put all the signal elements in an IsFirstTickOfBar section at the bottom of the OnBarUpdate section - must have just forgotten ninjascript... putting it to the test tomorrow in live market data.... thx

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by trilliantrader, 04-18-2024, 08:16 AM
          4 responses
          18 views
          0 likes
          Last Post trilliantrader  
          Started by mgco4you, Today, 09:46 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by wzgy0920, Today, 09:53 PM
          0 responses
          9 views
          0 likes
          Last Post wzgy0920  
          Started by Rapine Heihei, Today, 08:19 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 08:25 PM
          0 responses
          10 views
          0 likes
          Last Post Rapine Heihei  
          Working...
          X