Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PlaySound not playing

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

    PlaySound not playing

    Hello, I have created simple indicator which is using PlaySound function. I call the PlaySound function in following way: PlaySound(SoundAlertFile); and SoundAlertFile is string variable which is set to SoundAlertFile = NinjaTrader.Core.Globals.InstallDir + @"sounds\Alert1.wav";

    I have confirmed that the path is valid by calling the PlaySound function on each OnBarUpdate and the sound was played.

    Problem is that when the condition to play sound is met the sound is not playing. There are other indicators on the chart which should play sound on the same condition. When this problematic indicator is present the other sounds won't play. When it is removed they will play.

    Indicator draws dot and its color is changing according to the same condition which should play sound. Color changes correctly so I assume sound should be played as well.

    There are no errors logged in the Log tab in NT.

    Please see attached code. (Of course the variable EnableSoundAlerts is set to true)

    Code:
    protected override void OnBarUpdate()
    {
      if (w1[0] < w2[0] && w2[0] < w3[0] && w3[0] < w4[0] && w4[0] < w5[0])
      {
        alignmentUp = true;
        brush = AlignmentUpColor;
      }
      else
      {
        alignmentUp = false;
      }
    
      if (w1[0] > w2[0] && w2[0] > w3[0] && w3[0] > w4[0] && w4[0] > w5[0])
      {
        alignmentDown = true;
        brush = AlignmentDownColor;
      }
      else
      {
        alignmentDown = false;
      }
    
      if (alignmentUp != alignmentUpPrev)
      {
        if (EnableSoundAlerts)
        {
          DebugPrint("PlaySound");
          PlaySound(SoundAlertFile);
        }
      }
    
      if (alignmentDown != alignmentDownPrev)
      {
        if (EnableSoundAlerts)
        {
          DebugPrint("PlaySound");
          PlaySound(SoundAlertFile);
        }
      }
    
      alignmentUpPrev = alignmentUp;
      alignmentDownPrev = alignmentDown;
    }​
    Could you please help?

    Thanks in advance

    #2
    Hello 09try,

    Try closing all open workspaces and then test the test file attached to this post, is this able to reproduce?
    PlaySoundTest_NT8.zip

    With your script, may I confirm you are running this with Calculate set to OnBarClose?

    There are a lot of unknowns about the variable object types in your suggested code.

    May I have you copy the relevant code into a test script and then export this and attach the export?



    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea, thanks for answer. I have attached the indicator. I will test the PlaySoundTest and will let you know.

      Edit: I have tested the PlaySoundTest. I added a workplace with only one chart, no candles, only line and range and without any other indicator. Only the PlaySoundTest indicator. At first I didn't hear anything, then I restarted NT8 and at the second test I heard the sound 2 times but then no more. I have reinstalled NT8 with the same result.
      Attached Files
      Last edited by 09try; 09-28-2024, 04:56 AM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      576 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X