How to code a sound alert - futures io
futures io futures trading



How to code a sound alert


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Saroj with 3 posts (24 thanks)
    2. looks_two juliusnyny with 3 posts (0 thanks)
    3. looks_3 TheWizard with 2 posts (0 thanks)
    4. looks_4 max-td with 1 posts (0 thanks)
    1. trending_up 9,383 views
    2. thumb_up 29 thanks given
    3. group 11 followers
    1. forum 12 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

How to code a sound alert

(login for full post details)
  #1 (permalink)
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
 
Saroj's Avatar
 
Posts: 486 since Jun 2009
Thanks: 232 given, 413 received

Putting in a sound alert

Insert the following under “#region Variables”
-------------------------
private bool soundOn = true; // on/off switch for audio alerts
private string alert1Sound = "alert1.wav"; //audio alert for Condition1
private string alert2Sound ="alert2.wav"; //audio alert for Condition2
private bool Condition1 = false;//will be set to the conditions for alert1
private bool Condition2 = false; //will be set to the conditions for alert2
-------------------------
soundOnallows the user to turn sound on and off
The wav files will be displayed as the default wav files. With the entries in the Properties section, you can change them to something else.
The Condition variables are only necessary if you choose to use them to hold the results of your criteria.

Insert the following files under C:\ProgramFiles\NinjaTrader6.5\sounds (modify for your specific installation path if different; but note that this is the executables directory, not the data directory for NinjaTrader which is typically in the “My Documents” directory. “Directory” means same as “Folder”)
-------------------------
alert1.wav
alert2.wav
-------------------------
These are fictitious file names. Find a wav file that you want and either rename to these names or change the names in the Variables section to those you select.

Insert the following under “#region Properties “ – it doesn’t have to be directly below; just somewhere before the #endregion for “Properties”.

-------------------------
[Description("what will help the user decide how to choose their entry")]
[Category("Parameters")]
public string Alert1Sound
{
get { return alert1Sound; } // this name matches that in the Variables section
set { alert1Sound = value; }
}
[Description("what will help the user decide how to choose their entry ")]
[Category("Parameters")]
public string Alert2Sound
{
get { return alert2Sound; } // this name matches that in the Variables section
set { alert2Sound = value; }
}
-------------------------
The name following “public string” will display in the Parameter area in the indicator dialogue box in the left column. The Description will appear below the parameters when the user clicks on that entry box. Enter something like “Sound file to play for long alert”.

Insert the following under “OnBarUpdate()” at the place in your logic where you want the alert:
-------------------------
if (Condition1 && soundOn) PlaySound(alert1Sound);}
if (Condition2 && soundOn) PlaySound(alert2Sound);}

If you don't want your sound to play every tick of the bar when condition is met you can use:
if (Condition1 && soundOn && FirstTickOfBar) PlaySound(alert1Sound);
if (Condition2 && soundOn && FirstTickOfBar) PlaySound(alert2Sound);
-------------------------
Condition1 and Condition2 can be either boolean variables that have been set to your criteria or you can insert your boolean statement itself.

All of the names above in bold can be replaced by your own names; however where they are the same spelling as in the example, they must be so in your modifications as well. Also in the properties section, the name following “public string” must be spelled differently from the similar name following “return” and in the set statement. Typically this is accomplished by putting the first letter following “public string” in caps.

Started this thread Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(167 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(116 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #2 (permalink)
Norcross, Ga
 
Experience: Advanced
Platform: NinjaTrader, Tradestation, Think Or Swim
Broker: Mirus Zen-Fire
Trading: ES
 
Posts: 15 since Sep 2009
Thanks: 5 given, 1 received

Good Stuff. Thanks.

Reply With Quote
 
(login for full post details)
  #3 (permalink)
the coin hunter
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
 
cory's Avatar
 
Posts: 6,029 since Jun 2009
Thanks: 845 given, 7,893 received


a clear and concise guide of how to code the sound alert, excellent!

Reply With Quote
 
(login for full post details)
  #4 (permalink)
 
 
roonius's Avatar
 
Posts: 132 since Jun 2009
Thanks: 20 given, 287 received


Saroj View Post
Insert the following under “OnBarUpdate()” at the place in your logic where you want the alert:
-------------------------
if (Condition1 && soundOn) PlaySound(alert1Sound);
if (Condition2 && soundOn) PlaySound(alert2Sound);
-------------------------
Condition1 and Condition2 can be either boolean variables that have been set to your criteria or you can insert your boolean statement itself.


One small addition for those who run their indicators or strategies tick by tick (CalculateOnBarClose = false).

If you don't want your sound to play every tick of the bar when condition is met you can use:
if (Condition1 && soundOn && FirstTickOfBar) PlaySound(alert1Sound);
if (Condition2 && soundOn && FirstTickOfBar) PlaySound(alert2Sound);

Reply With Quote
The following 5 users say Thank You to roonius for this post:
 
(login for full post details)
  #5 (permalink)
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
 
max-td's Avatar
 
Posts: 1,754 since Jun 2009
Thanks: 2,309 given, 924 received

Just gotta say : Wow + ThanX saroj !

max-td
Reply With Quote
 
(login for full post details)
  #6 (permalink)
Here, GA
 
 
Posts: 157 since Jun 2009
Thanks: 1 given, 84 received

Saroj, Would you by chance have an Example of NT calling a C++ DLL in your bag of tricks? I have a mental block on this one. BTW very nice effort on the code and explanation above.

Reply With Quote
 
(login for full post details)
  #7 (permalink)
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
 
Saroj's Avatar
 
Posts: 486 since Jun 2009
Thanks: 232 given, 413 received


TAJTrades View Post
Saroj, Would you by chance have an Example of NT calling a C++ DLL in your bag of tricks? I have a mental block on this one. BTW very nice effort on the code and explanation above.

sorry TAJ, no... I'm just learning NS/C#.. but I'll bet there are examples in the NT forum... please post if you find one.

Started this thread Reply With Quote
 
(login for full post details)
  #8 (permalink)
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
 
Saroj's Avatar
 
Posts: 486 since Jun 2009
Thanks: 232 given, 413 received


roonius View Post
One small addition for those who run their indicators or strategies tick by tick (CalculateOnBarClose = false).

If you don't want your sound to play every tick of the bar when condition is met you can use:
if (Condition1 && soundOn && FirstTickOfBar) PlaySound(alert1Sound);
if (Condition2 && soundOn && FirstTickOfBar) PlaySound(alert2Sound);

thanks roonius... if anyone else has suggestions or enhancements.. please feel free

Started this thread Reply With Quote
 
(login for full post details)
  #9 (permalink)
Yonkers, NY/USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: SI
 
Posts: 5 since Mar 2012
Thanks: 3 given, 4 received

"Insert the following under “OnBarUpdate()” at the place in your logic where you want the alert:"

This code is great so thank you so much, but I need just a little more help since I'm not well versed in programming. I have an indicator I'm trying to add sound to. I have done what I can to follow your directions but need help in finding the "place in my logic" to add this part of the code.

Many Thanks,
Julius

Reply With Quote
 
(login for full post details)
  #10 (permalink)
Houston, TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Optimus Futures, AMP, CQG
Trading: 6E
 
TheWizard's Avatar
 
Posts: 1,736 since Jun 2009
Thanks: 517 given, 4,214 received



juliusnyny View Post
"Insert the following under “OnBarUpdate()” at the place in your logic where you want the alert:"

This code is great so thank you so much, but I need just a little more help since I'm not well versed in programming. I have an indicator I'm trying to add sound to. I have done what I can to follow your directions but need help in finding the "place in my logic" to add this part of the code.

Many Thanks,
Julius

@juliusnyny,

You can always post a request in the "Want your Ninjatrader indicator created free?" thread. If you upload the indicator, I'm sure someone (myself included) would be most happy to add the code for you, at the precise point in the logic where you want it. Then you can see how it's done & go from there.

After all, it's what you learn AFTER you know it all, that counts!
Reply With Quote
 
(login for full post details)
  #11 (permalink)
Yonkers, NY/USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: SI
 
Posts: 5 since Mar 2012
Thanks: 3 given, 4 received

Thanks Wizard, that sounds great. I haven't been able to find that thread so far. I've already inserted the code into the indicator except that last part hasn't been done correctly or at all. May I send it to you, or will you give me a link to the "want your ninjatrader indicator for free" thread?

Thanks,
Julius

Reply With Quote
 
(login for full post details)
  #12 (permalink)
Houston, TX
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Optimus Futures, AMP, CQG
Trading: 6E
 
TheWizard's Avatar
 
Posts: 1,736 since Jun 2009
Thanks: 517 given, 4,214 received


juliusnyny View Post
Thanks Wizard, that sounds great. I haven't been able to find that thread so far. I've already inserted the code into the indicator except that last part hasn't been done correctly or at all. May I send it to you, or will you give me a link to the "want your ninjatrader indicator for free" thread?

Thanks,
Julius

@juliusnyny,

It's an "elite" thread.



That's probably why you couldn't find it. You can Private Message the indicator to me, or upload it here to your thread. I'll be happy to help, if I can.

After all, it's what you learn AFTER you know it all, that counts!
Reply With Quote
 
(login for full post details)
  #13 (permalink)
Yonkers, NY/USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: SI
 
Posts: 5 since Mar 2012
Thanks: 3 given, 4 received

Hi Wizard. I tried to send it to you by private message but apparently I only have 3 posts to my name and one needs 5 in order to private message. I only just now realized you hadn't received it since this is the 1st I've seen of your response. I'll try to attach it but there may be some rule forbidding it. Thanks.
Julius

Attached Files
Register to download File Type: zip KnoxvilleDivergence.zip (8.1 KB, 30 views)
Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > How to code a sound alert


Last Updated on September 27, 2015


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts