I am trying to create an Alert that shows me the crossover of one or two EMAs with a DMA. Can anybody help me. I have searched the entire Database for similar files. Can only find crossovers of Close/MA.
Thanks
Thanks
var vMA1 = new MAStudy(1, 0, "Close" , MAStudy.SIMPLE);
var vMA2 = new MAStudy(5, 0, "Close" , MAStudy.SIMPLE);
function preMain() {
setPriceStudy(true);
setStudyTitle("MAx2(one alert)");
setCursorLabelName("MA1", 0);
setCursorLabelName("MA2", 1);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.red, 1);
}
var vFlag1 = 0;
var vFlag2 = 0;
function main() {
//this section determines the relative position of the averages at the prior bar
//and sets the Flags accordingly
if(getBarState() == BARSTATE_NEWBAR){
if(vMA1.getValue(MAStudy.MA,-1) > vMA2.getValue(MAStudy.MA,-1)){
vFlag1 = 1;
vFlag2 = 1;
}
if(vMA1.getValue(MAStudy.MA,-1) < vMA2.getValue(MAStudy.MA,-1)){
vFlag1 = -1;
vFlag2 = -1;
}
}
//the following section triggers alerts only in the direction determined by the code above
//if crossing over
if(vFlag1 == -1){
if(vMA1.getValue(MAStudy.MA) > vMA2.getValue(MAStudy.MA) && vFlag2 == -1){
Alert.playSound("ding.wav");
Alert.addToList(getSymbol()+" "+getInterval(),"Crossing Up",Color.black,Color.blue);
vFlag2 = 1;
}
if(vMA1.getValue(MAStudy.MA) < vMA2.getValue(MAStudy.MA) && vFlag2 == 1){
vFlag2 = -1;
}
}
//if crossing under
if(vFlag1 == 1){
if(vMA1.getValue(MAStudy.MA) < vMA2.getValue(MAStudy.MA) && vFlag2 == 1){
Alert.playSound("buzz.wav");
Alert.addToList(getSymbol()+" "+getInterval(),"Crossing Down",Color.black,Color.red);
vFlag2 = -1;
}
if(vMA1.getValue(MAStudy.MA) > vMA2.getValue(MAStudy.MA) && vFlag2 == -1){
vFlag2 = 1;
}
}
return new Array (vMA1.getValue(MAStudy.MA),vMA2.getValue(MAStudy.MA));
}
Comment