Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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.
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);
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.
"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.
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!