NexusFi: Find Your Edge


Home Menu

 





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 11,517 views
    2. thumb_up 29 thanks given
    3. group 11 followers
    1. forum 12 posts
    2. attach_file 1 attachments




 
Search this Thread

How to code a sound alert

  #1 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415

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

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Better Renko Gaps
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
22 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #2 (permalink)
 sp139214 
Norcross, Ga
 
Experience: Advanced
Platform: NinjaTrader, Tradestation, Think Or Swim
Broker: Mirus Zen-Fire
Trading: ES
Posts: 15 since Sep 2009
Thanks Given: 5
Thanks Received: 1

Good Stuff. Thanks.

Reply With Quote
  #3 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090


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

Reply With Quote
  #4 (permalink)
 
roonius's Avatar
 roonius   is a Vendor
 
Posts: 131 since Jun 2009
Thanks Given: 20
Thanks Received: 295


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
Thanked by:
  #5 (permalink)
 
max-td's Avatar
 max-td 
Frankfurt
 
Experience: Intermediate
Platform: NinjaTrader
Trading: FGBL 6E B4
Posts: 1,752 since Jun 2009
Thanks Given: 2,309
Thanks Received: 927

Just gotta say : Wow + ThanX saroj !

max-td
Reply With Quote
  #6 (permalink)
TAJTrades
Here, GA
 
Posts: 158 since Jun 2009
Thanks Given: 1
Thanks Received: 86

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
  #7 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415


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
  #8 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415


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
  #9 (permalink)
 juliusnyny 
Colorado Springs, CO/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: CL
Posts: 9 since Mar 2012
Thanks Given: 6
Thanks Received: 4

"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
  #10 (permalink)
 
TheWizard's Avatar
 TheWizard 
Houston, TX
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Optimus Futures, AMP, CQG
Trading: 6E
Posts: 1,731 since Jun 2009
Thanks Given: 517
Thanks Received: 4,224



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




Last Updated on September 27, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts