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

constant sound

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

    constant sound

    I am trying to get a sound to constantly play for 1 minute. I have the following code and the sound plays on each new bar. How do I get it to play constantly for the 1 minute.

    protectedoverridevoid OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(Close[0]);
    if (CurrentBar < (5))
    return;

    if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 74600)
    {PlaySound(
    @"C:\Program Files\NinjaTrader 6.5\sounds\Alert1.wav");}

    #2
    If calculateonbarclose = true, it will only call OnBarUpdate once per Close.

    If false, it will call it each tick, which could be quite annoying for sounds, so you might want to do some more code to call it every 10 ticks or 20 ticks, etc. (use a local variable like x, and increment it, then reset it on firsttickofbar).

    // variables

    private int x = 0;

    // initialize

    CalculateOnBarClose = false;

    // onbarupdate

    if (FirstTickOfBar)
    x = 0;

    if (x > 10)
    { PlaySound(); x=0; }
    else
    x++;


    Just typed this haven't tested, but should be general idea.

    Mike

    Comment


      #3
      Thanks, I will give it a try

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ftsc2022, 10-25-2022, 12:03 PM
      5 responses
      255 views
      0 likes
      Last Post KeyonMatthews  
      Started by ScottW, Today, 06:09 PM
      0 responses
      2 views
      0 likes
      Last Post ScottW
      by ScottW
       
      Started by Board game geek, 10-29-2023, 12:00 PM
      14 responses
      244 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Waxavi, 04-19-2024, 02:10 AM
      4 responses
      56 views
      0 likes
      Last Post sonia0101  
      Started by cmtjoancolmenero, Today, 03:58 PM
      0 responses
      9 views
      0 likes
      Last Post cmtjoancolmenero  
      Working...
      X