NexusFi: Find Your Edge


Home Menu

 





Let's teach Sierra Chart how to talk


Discussion in Sierra Chart

Updated
    1. trending_up 2,509 views
    2. thumb_up 10 thanks given
    3. group 4 followers
    1. forum 3 posts
    2. attach_file 3 attachments




 
Search this Thread

Let's teach Sierra Chart how to talk

  #1 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

The title of this thread is a tribute to the thread " Let's Teach [AUTOLINK]NinjaTrader[/AUTOLINK] how to talk" thanks to which I have learnt that Windows has built-in speech generation capability, and which gives some code example for NinjaTrader.

Objective: have Sierra Chart speak "New Candle" at each new candle
Of course, this is not very useful. But the idea is that the code may be adapted for other uses, as sophisticated alerts.

Important disclaimer. I am a total newbie in C++, .NET, Windows programming, etc. I have solved all my Windows-related problems by Googling. And I am not sure to have understood what I have done. What follows is experimental, may be dirty and non-optimal. If another nexusfi.com (formerly BMT) member wants to improve this solution, she/he shall not hesitate!

1. Open a new solution in Visual C++ with the 40-line code below.
Do not forget to adapt the first line to reflect the exact directory of your sierrachart.h
Do not forget to update the output .DLL directory (as usual)

2. Try to build the solution.
You should obtain the following error message: fatal error C1190: managed targeted code requires a '/clr' option
Go to Properties of the solution >> Configuration Properties >> General >> Common Language Runtime Support
Choose "Common Language Runtime Support (/clr)"

Reference : managed targeted code requires a /clr option


3. Try to build the solution.
You should obtain the following error message: Command line error D8016 : '/MT' and '/clr' command-line options are incompatible
Go to Properties of the solution >> Configuration Properties >> C++ >> Code Generation >> Runtime Library
Choose "Multi-threaded DLL (/MD)"

References : '/MT' and '/clr' command-line options are incompatible and /MD, /MT, /LD (Use Run-Time Library)


4. Try to build the solution.
You should obtain the following error message: fatal error C1107: could not find assembly 'System.Speech.dll': please specify the assembly search path using /AI or by setting the LIBPATH environment variable
Go to Properties of the solution >> Configuration Properties >> C++ >> General >> Resolve #using References
Add the directory of System.Speech.dll

On my computer, this directory is:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\
Reference: /AI (Specify Metadata Directories) (C++)


5. Try to build the solution: should be OK!
Then add the study "Voice" to your chart, as usual.
You should hear "Hello" once or twice.
And "New candle" at each new candle.

6. Some links for my own reference:
On #pragma managed: managed type or function cannot be used in an unmanaged function - .NET Framework and Mixing Managed and Unmanaged code - CodeProject
On managed global variable: compile error: may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
On gcnew and ^ : C3673: class does not have a copy-constructor
"A Very Easy Introduction to Microsoft .NET Speech Synthesis (VB, C#, C++)": A Very Easy Introduction to Microsoft .NET Speech Synthesis (VB, C#, C++) - CodeProject
Reference of Microsoft Speech API: Microsoft Speech API (SAPI) 5.3 and System.Speech Namespaces ()


Once more, the above is experimental. It may exist cleaner solutions.

Nicolas

 
Code
#include "C:\Sierrachart-IQFeed\ACS_Source\sierrachart.h"

#using <System.dll>
#using <System.Speech.dll>
using namespace System::Speech::Synthesis;

SCDLLName("Voice")

#pragma managed
public ref class Globals abstract sealed {
public:
   static SpeechSynthesizer^ speaker = gcnew SpeechSynthesizer();
};

#pragma managed
SCSFExport scsf_Voice(SCStudyGraphRef sc)
{

	// Persistent variable:
	int& LastScIndex = sc.PersistVars->i1;

	if ( sc.SetDefaults )
	{	
		sc.GraphName = "Voice";
		sc.StudyDescription = "Voice";
		sc.AutoLoop = 1;
		sc.FreeDLL = 1;

		Globals::speaker->SpeakAsync("Hello");

		return;
	}

	if ( sc.Index == 0 ) LastScIndex = -1;

	// If new candle...
	if ( sc.Index != LastScIndex ) {
		LastScIndex = sc.Index;
		// If in real-time, let's talk!
		if ( sc.Index == sc.ArraySize-1 ) {
			Globals::speaker->SpeakAsync("New candle");
		}
	}
}

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603


Dude, you are on a roll!

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

A code a little bit cleaner. I have put in bold all the specific parts related to the voice.

 
Code
#include "C:\Sierrachart-IQFeed\ACS_Source\sierrachart.h"

#using <System.dll>
#using <System.Speech.dll>

using namespace System;
using namespace System::Speech::Synthesis;

#pragma managed
public ref class Globals abstract sealed {
public:
   static SpeechSynthesizer^ speaker = gcnew SpeechSynthesizer();
};

SCDLLName("Voice")

SCSFExport scsf_Voice(SCStudyGraphRef sc)
{

	// Persistent variable:
	int& LastScIndex = sc.PersistVars->i1;

	if ( sc.SetDefaults ) {	
		sc.GraphName = "Voice";
		sc.StudyDescription = "Voice";
		sc.AutoLoop = 1;
		sc.FreeDLL = 1;

		return;
	}

	if ( sc.LastCallToFunction ) {
		delete Globals::speaker;
	}

	if ( sc.Index == 0 ) LastScIndex = -1;

	// If new candle...
	if ( sc.Index != LastScIndex ) {
		LastScIndex = sc.Index;
		// If in real-time, let's talk!
		if ( sc.Index == sc.ArraySize-1 ) {
			Globals::speaker->SpeakAsync("New candle");
		}
	}
}

Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:




Last Updated on August 18, 2012


© 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