NexusFi: Find Your Edge


Home Menu

 





Using Async Voice Synthesizer Alerts


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one vantojo with 4 posts (5 thanks)
    2. looks_two jmont1 with 4 posts (0 thanks)
    3. looks_3 Tasker_182 with 2 posts (2 thanks)
    4. looks_4 Zondor with 1 posts (1 thanks)
    1. trending_up 4,473 views
    2. thumb_up 8 thanks given
    3. group 7 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread

Using Async Voice Synthesizer Alerts

  #1 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Hello,

I am starting to play around a little with synthetic voice alerts and found that the Speak method is synchronous and locks the execution thread while it is playing the voice. So, the Ninja script and the Ninja Chart Draw basically stop until the voice is played.

Also, in Synchronous mode, when lots of alerts come quickly, they are queued up and all NT tasks seem to lock up, even on a fast multi thread machine, until the voice synthesizer queue is emptied.

It appears that the Async mode solves this problem. Alerts are not queued and are allowed to speak over each other...which for me is better than queueing up 10 audio alerts in a fast market

You can try this out yourself with the following indicator...just alternately comment out the Speak and SpeakAsync lines....and then run it on a fast moving chart, with fast bars, such as say, a 2 range bar, to push lots of alerts quickly.

Here is some code to play with....

 
Code
                            
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Speech.Synthesis;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// NOTE:  Before this will compile successfully, you need to put the following in the References
// C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.Speech.dll
//
// to do this, 
// 1) open an Indicator in the Editor
// 2) right mouse click in the text area
// 3) click References
// 4) click Add
// 5) browse to the location above and add it to the NT References
// 

// this script is set up for Futures...for example
// for CME Gold, Instrument.MasterInstrument = "GC" 
// the substrings break this into "G C" so that each letter is spoken


namespace NinjaTrader.Indicator
{


    public class 
AAVoice Indicator
    
{
        
#region Variables
        
        
private SpeechSynthesizer voice
        
string    Words;
        
        
#endregion

        
protected override void Initialize()
        {
            
Overlay                false;
        }

    
        protected 
override void OnBarUpdate()
        {
            if (
Historical) return;
            
            
Words Instrument.MasterInstrument.Name.Substring(0,1) + 
                    
" " +
                    
Instrument.MasterInstrument.Name.Substring(1,1) + 
                    
" New Bar";
            
//            voice.Speak (Words);
            
voice.SpeakAsync (Words);
            
            Print (
"Speak ==> " Words);
        }

        
    protected 
override void OnStartUp()
        {
            
voice = new SpeechSynthesizer();
        }

        protected 
override void OnTermination()
        {
            
voice.Dispose();
        }


        
#region Properties
        #endregion
    
}


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
67 thanks
NexusFi site changelog and issues/problem reporting
47 thanks
Battlestations: Show us your trading desks!
43 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #3 (permalink)
 jmont1 
New York, NY
 
Experience: Intermediate
Platform: NinjaTrader8
Broker: Data = Rithmic -- Gives 70 Level II Data
Trading: 6C (Low Margin,) 6E, CL, GC, ES and Maybe DX for smaller tick value
Posts: 1,394 since May 2011
Thanks Given: 1,719
Thanks Received: 1,019



vantojo View Post
Hello,

I am starting to play around a little with synthetic voice alerts and found that the Speak method is synchronous and locks the execution thread while it is playing the voice. So, the Ninja script and the Ninja Chart Draw basically stop until the voice is played.

Also, in Synchronous mode, when lots of alerts come quickly, they are queued up and all NT tasks seem to lock up, even on a fast multi thread machine, until the voice synthesizer queue is emptied.

It appears that the Async mode solves this problem. Alerts are not queued and are allowed to speak over each other...which for me is better than queuing up 10 audio alerts in a fast market

@vantojo, would the standard Ninja Trader indicator "Candle Stick Pattern" be a good candidate for synthesis? I use about 2 - 4 pairs of this indicator, Engulfing pairs, Morning Star/Evening Star and others. They do not signal that often and if you were to use a rearm function of perhaps 55 seconds I would think it should not disrupt processing much.

Any chance you would code this with alert stating "doji" type: Bearish Engulfing 6E 2 minute?

That would be awesome. I already have separate Engulfing indicator but it simply says engulfing. Hopefully you could provide at least a first pass at this?

Reply With Quote
  #4 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

Hi,

I'm totally focused at the moment on a development project....perhaps another coder can help you? Integrating the voice is easy, as the code above shows...that is all you need to do.

Good luck!

Started this thread Reply With Quote
  #5 (permalink)
 jmont1 
New York, NY
 
Experience: Intermediate
Platform: NinjaTrader8
Broker: Data = Rithmic -- Gives 70 Level II Data
Trading: 6C (Low Margin,) 6E, CL, GC, ES and Maybe DX for smaller tick value
Posts: 1,394 since May 2011
Thanks Given: 1,719
Thanks Received: 1,019


vantojo View Post
Hi,

I'm totally focused at the moment on a development project....perhaps another coder can help you? Integrating the voice is easy, as the code above shows...that is all you need to do.

Good luck!

vantojo, Can get it speak, but like Donkey in the movie Shrek, it won't shut up? It keeps repeating the Words instead of just speaking it once:

// voice.Speak (Words);

voice.SpeakAsync (Words);

Print ("Speak ==> " + Words);

//JMont1 End
patternsFound++;
Value.Set(1);
}
#endregion
break;


Any ideas?

Now looking at TrendLineTalkingAlert that has info similar to Tasker_182 logic.

Reply With Quote
  #6 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401

You need a conditional statement that allows the voice alert once per bar, assuming you are COBC= false.

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
  #7 (permalink)
 jmont1 
New York, NY
 
Experience: Intermediate
Platform: NinjaTrader8
Broker: Data = Rithmic -- Gives 70 Level II Data
Trading: 6C (Low Margin,) 6E, CL, GC, ES and Maybe DX for smaller tick value
Posts: 1,394 since May 2011
Thanks Given: 1,719
Thanks Received: 1,019


Tasker_182 View Post
You need a conditional statement that allows the voice alert once per bar, assuming you are COBC= false.

@Tasker_182, Yes, I am tryinng to use COBC = false. The same thing happens to the sample text in post #1 if COBC=False is used.

Any idea what type of statement would apply to have that happen? I tried looking at the "Rearm" statement used for Alerts but it does not look like it applies. I was thinking there might be a "Stop" type statement for voice.

Thought about doing words "" but then I think the syntesis would still be active, just quiet, but still procesing.

Any assistance would be apprecited, Tasker or @vantojo.

Reply With Quote
  #8 (permalink)
 
Tasker_182's Avatar
 Tasker_182 
Cedar Rapids, iowa
Legendary Market Wizard
 
Experience: Intermediate
Platform: Ninjatrader
Broker: Ninjatrader - Continuum
Posts: 716 since Aug 2009
Thanks Given: 476
Thanks Received: 1,401

This isn't easy on my iPhone but basically you want to test if your condition (whatever it is, is true) in order to speak the words. Using the system variable FirstTickOfBar will only be true once per bar. Saidstuff is your bool variable to mean if words have been or could be spoken. Saidstuff is set false at the beginning of each bar

If your condition is true and saidstuff is false then the words are spoken and then saidstuff is set true so that words won't be spoken until the next bar (and your condition is true).

If (your condition is true)
{
If (FirstTickOfBar) saidstuff = false;
If (!saidstuff)
{
(Speak the words you want to say)
saidstuff = true;
}
}

Be yourself; everyone else is already taken. Oscar Wilde
Reply With Quote
The following 2 users say Thank You to Tasker_182 for this post:
  #9 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012

you can also make a timer....so that it only speaks again after a certain number of seconds

not at my coding computer but psuedo code is this (translate to C#)

datetime lastalert = now



if time difference seconds (now - last_alert ) > 10 // only voice every 10 seconds
{
speak
lastalert = now
}



the Ninja Alert has a built in rearm capability, the voice does not, you have to code it like above

Started this thread Reply With Quote
  #10 (permalink)
 vantojo 
Vilcabamba, Ecuador
 
Experience: Intermediate
Platform: Ninja
Trading: NQ, UB
Posts: 204 since Jul 2012


in the example above now would be Time[0]

Started this thread Reply With Quote





Last Updated on July 4, 2014


© 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