Alert once for fresh condition(Help)

Questions about MultiCharts and user contributed studies.
goldmine
Posts: 6
Joined: 22 Oct 2014
Has thanked: 4 times

Alert once for fresh condition(Help)

Postby goldmine » 13 Feb 2015

I've written code to alert when MA9 corss MA18(for example)
but when I excute the alert in 10 minites time frame
the Alert keeps triggered every 10 minute.
What I need is that it triggered once only until next condition meet again.

Thanks

Code: Select all

input:QQ(168), a1(9), a2(18);
var:ma1(0),ma2(0);
ma1=average(close,a1);
ma2=average(close,a2);
condition1= CurrentBar > 1 and ma1 cross over ma2;
condition2= CurrentBar > 1 and ma1 cross under ma2;
if condition1 or condition2 then
playsound("d:\sound\GC.wav") ;
Alert(GetSymbolName);

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Alert once for fresh condition(Help)

Postby MAtricks » 13 Feb 2015

Cleaned up the code for you:

Code: Select all

INPUTS:
QQ( 168 ),
A1( 9 ),
A2( 18 ) ;

VARIABLES:
Ma1(0),
Ma2(0);

Ma1 = Average( C, A1 ) ;
Ma2 = Average( C, A2 ) ;

if Ma1 crossed over Ma2 then Alert( GetSymbolName ) ;
if Ma1 crossed under Ma2 then Alert( GetSymbolName ) ;
Also, check your alert settings setting and apply the sound file here:

Image
Attachments
alert box.jpg
(77.26 KiB) Downloaded 557 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Alert once for fresh condition(Help)

Postby TJ » 21 Feb 2015

I've written code to alert when MA9 corss MA18(for example)
but when I excute the alert in 10 minites time frame
the Alert keeps triggered every 10 minute.
What I need is that it triggered once only until next condition meet again.

Thanks

Code: Select all

input:QQ(168), a1(9), a2(18);
var:ma1(0),ma2(0);
ma1=average(close,a1);
ma2=average(close,a2);
condition1= CurrentBar > 1 and ma1 cross over ma2;
condition2= CurrentBar > 1 and ma1 cross under ma2;
if condition1 or condition2 then
playsound("d:\sound\GC.wav") ;
Alert(GetSymbolName);
The problem is in your code...
you need a BEGIN and END block.

Code: Select all


input:QQ(168), a1(9), a2(18);
var:ma1(0),ma2(0);

ma1=average(close,a1);
ma2=average(close,a2);
condition1= CurrentBar > 1 and ma1 cross over ma2;
condition2= CurrentBar > 1 and ma1 cross under ma2;

if condition1 or condition2 then
BEGIN
playsound("d:\sound\GC.wav") ;
Alert(GetSymbolName);
END;

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 288 times

Re: Alert once for fresh condition(Help)

Postby MAtricks » 21 Feb 2015

Hence the clean up I provided of that mess :)


Return to “MultiCharts”