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

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 judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        21 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        10 views
        0 likes
        Last Post cre8able  
        Working...
        X