How to prevent Say() function from going in a loop?

#1
I am using the Say() function to say the name of the script and "Buy" or "Sell" when Buy or Sell is generated. It works as intended when used on 1 script at a time: a signal is generated, I hear it once and that's it. But I am facing a problem when I have several charts loaded. Since I have the same formula in all the charts and I have several charts up on the screen at the same time. It so happens that when a buy or sell is generated for different scripts at the same time, the say function gets in a loop and keeps repeating the Say() function. Any workaround for that?

Code:
function SayOnce( text )
{
    if ( StaticVarGetText( "lastsaidtextr" ) != text )
    {
        Say( text , False );
        StaticVarSetText( "lastsaidtextr", text );
    }
}
I call it like this:

Code:
 SayOnce( Name() + "Going Long" );
 

mastermind007

Well-Known Member
#2
I am using the Say() function to say the name of the script and "Buy" or "Sell" when Buy or Sell is generated. It works as intended when used on 1 script at a time: a signal is generated, I hear it once and that's it. But I am facing a problem when I have several charts loaded. Since I have the same formula in all the charts and I have several charts up on the screen at the same time. It so happens that when a buy or sell is generated for different scripts at the same time, the say function gets in a loop and keeps repeating the Say() function. Any workaround for that?

Code:
function SayOnce( text )
{
    if ( StaticVarGetText( "lastsaidtextr" ) != text )
    {
        Say( text , False );
        StaticVarSetText( "lastsaidtextr", text );
    }
}
I call it like this:

Code:
 SayOnce( Name() + "Going Long" );

// Function to provide voice warning whenever any new trades are created
function SayItButNotTooOften( textToSay, minimumMilliSecondsToWait )
{
//Caveat: this function relies on Windows API QueryPerformanceCounter function and CPU RTDSC instruction and it may yield
// inaccurrate results if you have multiple-core processor and AMD's "Cool and Quiet" enabled in BIOS or other CPU clock
// stepping technologies enabled. If this applies to you, please contact support for resolution.

elapsed = GetPerformanceCounter()/1000;
Lastelapsed = Nz( StaticVarGet("lastspeaktime") );

if(elapsed - Lastelapsed > minimumMilliSecondsToWait)
{
StaticVarSet("lastspeaktime", elapsed );
Say( textToSay );
}
}
///////////////////////////////////////////////////////////////////////
 

Similar threads