I hv written below EFS to give alert when the EMA is touched. It is supposed to give alert only once per bar. However, it keeps on sending out alerts for the same bar. Any advice? thx
PHP Code:
var nEMALength = 20;
var bEMAAlert0 = false;
var EMAAlert0Mode = 0;
var EMAButton0Text = "this EMA";
var EMAButton0Color = Color.grey;
var EMAAlert0Sound = "thisEMAalert.wav";
function preMain()
{
setPriceStudy(true);
}
function main()
{
dThisEMA = ema(nEMALength);
RichButtons();
if( getBarState() == BARSTATE_ALLBARS ) {
thisInterval = getInterval();
thisSymbol = getSymbol();
}
if ( high()>=dThisEMA && low()<=dThisEMA ) {
if (EMAAlert0Mode==1 && !bEMAAlert0) {
Alert.addToList(thisSymbol, thisInterval+" :EMA is touched", Color.black, Color.purple);
Alert.playSound(EMAAlert0Sound);
}
bEMAAlert0 = true;
} else
bEMAAlert0 = false;
return;
}
function EMAButton0CallBack(nButtonPressed) {
if (EMAAlert0Mode == 0){
EMAAlert0Mode = 1;
EMAButton0Color = Color.cyan;
} else {
EMAAlert0Mode = 0;
EMAButton0Color = Color.grey;
}
RichButtons();
return;
}
function RichButtons(){
drawTextAbsolute(0, 70, EMAButton0Text+"@URL=EFS:EMAButton0CallBack",
Color.black, EMAButton0Color,
Text.RELATIVETOTOP | Text.RELATIVETOLEFT | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 10,
"EMAButton0");
return;
}
Comment