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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        115 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        66 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        101 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        91 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        78 views
        0 likes
        Last Post CarlTrading  
        Working...
        X