Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Re-arming a sound file

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

    Re-arming a sound file

    I am using a soundfile in a 5Min chart but don't want it to sound every 10 seconds or so for a full 5 minutes.

    I have used
    Alert("myAlert", NinjaTrader.Cbi.Priority.High, "ColoredCandle", soundFilelo, str, Color.Black, Color.Yellow);
    whereby I made "str" (Seconds to ReArm) user definable. Works fine.

    Question:
    Is it possible to use str also with:

    PlaySound(soundFilelo);

    and if so, how would that be expressed code-wise?

    sandman

    #2
    Originally posted by sandman View Post
    I am using a soundfile in a 5Min chart but don't want it to sound every 10 seconds or so for a full 5 minutes.

    I have used
    Alert("myAlert", NinjaTrader.Cbi.Priority.High, "ColoredCandle", soundFilelo, str, Color.Black, Color.Yellow);
    whereby I made "str" (Seconds to ReArm) user definable. Works fine.

    Question:
    Is it possible to use str also with:

    PlaySound(soundFilelo);

    and if so, how would that be expressed code-wise?

    sandman
    Hi,

    Rearm does not work with PlaySound.

    Sounds like you are using CalculateOnBarClose=False, so that means your code operates on every tick. If you want to use PlaySound that triggers once per bar, here is some code to do that.

    In the variables section declare

    private bool playOnce = true;

    in the OnBarUpdate section, within your logic condition

    (your condition = true)
    {
    if (playOnce)
    {
    PlaySound(soundFilelo)
    playonce = false; // prevent from playing until reset
    }

    if (FirstTickOfbar)
    {
    playOnce = true; // reset sound flag once per bar
    }

    Hope that helps.

    Comment


      #3
      Originally posted by Tasker-182 View Post
      Hi,
      Rearm does not work with PlaySound.

      Sounds like you are using CalculateOnBarClose=False, so that means your code operates on every tick. If you want to use PlaySound that triggers once per bar, here is some code to do that.
      ....
      Hope that helps.
      Thanks Tasker. I'll work with that.
      sandman

      Comment


        #4
        Originally posted by sandman View Post
        Thanks Tasker. I'll work with that.
        sandman
        I had a slight error, the system bool is FirstTickOfBar - the capitalizing is needed.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        607 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        353 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X