Is there a way to make the following formula have a selectable option for Pop up and Sound? Can you also make the sounds selectable to differentiate between alerts set in charts? Thank you.
/************************************************** *******
Alexis C. Montenegro © July 2003
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
Modified basicmax3(alerts).efs 2009 to use only 2 MAs and be listed on Alert List
1/31/12 Modified to add color, style, and make alerts real-time
************************************************** ********/
var vMA1 = null;
var vMA2 = null;
var bInit = false;
function preMain() {
setPriceStudy(true);
setStudyTitle("Alert2MaxOver3");
setShowTitleParameters(false);
setCursorLabelName("Fast MA", 0);
setCursorLabelName("Slow MA", 1);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
var fp1 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
fp1.setName("Fast MA");
fp1.setLowerLimit(1);
fp1.setDefault(13); //Edit this value to set a new default
var fp2 = new FunctionParameter("MA1Offset", FunctionParameter.NUMBER);
fp2.setName("Fast MA Offset");
fp2.setDefault(0); //Edit this value to set a new default
var fp3 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
fp3.setName("Fast MA Source");
fp3.addOption("Close");
fp3.addOption("High");
fp3.addOption("Low");
fp3.addOption("Open");
fp3.addOption("HL/2");
fp3.addOption("HLC/3");
fp3.addOption("OHLC/4");
fp3.setDefault("Close"); //Edit this value to set a new default
var fp4 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
fp4.setName("Fast MAType");
fp4.addOption("MAStudy.SIMPLE");
fp4.addOption("MAStudy.EXPONENTIAL");
fp4.addOption("MAStudy.WEIGHTED");
fp4.addOption("MAStudy.VOLUMEWEIGHTED");
fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp5 = new FunctionParameter("Color1", FunctionParameter.COLOR);
fp5.setName("LFast MA Line Color");
fp5.setDefault(Color.red);
var fp6 = new FunctionParameter("Style1", FunctionParameter.STRING);
fp6.setName("Fast MA Style");
fp6.addOption("PS_SOLID");
fp6.addOption("PS_DASH");
fp6.addOption("PS_DOT");
fp6.setDefault("PS_SOLID");
var fp7 = new FunctionParameter("MA2Length", FunctionParameter.NUMBER);
fp7.setName("Slow MA");
fp7.setLowerLimit(1);
fp7.setDefault(50); //Edit this value to set a new default
var fp8 = new FunctionParameter("MA2Offset", FunctionParameter.NUMBER);
fp8.setName("Slow MA Offset");
fp8.setDefault(0); //Edit this value to set a new default
var fp9 = new FunctionParameter("MA2Source", FunctionParameter.STRING);
fp9.setName("Slow MA Source");
fp9.addOption("Close");
fp9.addOption("High");
fp9.addOption("Low");
fp9.addOption("Open");
fp9.addOption("HL/2");
fp9.addOption("HLC/3");
fp9.addOption("OHLC/4");
fp9.setDefault("Close"); //Edit this value to set a new default
var fp10 = new FunctionParameter("MA2Type", FunctionParameter.STRING);
fp10.setName("Slow MA Type");
fp10.addOption("MAStudy.SIMPLE");
fp10.addOption("MAStudy.EXPONENTIAL");
fp10.addOption("MAStudy.WEIGHTED");
fp10.addOption("MAStudy.VOLUMEWEIGHTED");
fp10.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp11 = new FunctionParameter("Color2", FunctionParameter.COLOR);
fp11.setName("Slow MA Line Color");
fp11.setDefault(Color.blue);
var fp12 = new FunctionParameter("Style2", FunctionParameter.STRING);
fp12.setName("Slow MA Style");
fp12.addOption("PS_SOLID");
fp12.addOption("PS_DASH");
fp12.addOption("PS_DOT");
fp12.setDefault("PS_SOLID");
}
function main(MA1Length,MA1Offset,MA1Source,MA1Type,Color1, Style1,MA2Length,MA2Offset,MA2Source,MA2Type,Color 2,Style2) {
if(bInit == false){
setDefaultBarFgColor(Color1,0);
setDefaultBarFgColor(Color2,1);
setDefaultBarStyle(eval(Style1),0);
setDefaultBarStyle(eval(Style2),1);
bInit = true;
}
if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Offset, MA1Source, eval(MA1Type));
if (vMA2 == null) vMA2 = new MAStudy(MA2Length, MA2Offset, MA2Source, eval(MA2Type));
if(getBarState()==BARSTATE_NEWBAR){
if(vMA1.getValue(MAStudy.MA,0) >= vMA2.getValue(MAStudy.MA,0) && vMA1.getValue(MAStudy.MA,-1) <= vMA2.getValue(MAStudy.MA,-1)) {
Alert.addToList(getSymbol(), "Fast MA >= Slow MA", Color.black, Color.green);
Alert.playSound("ding.wav");
}
if(vMA1.getValue(MAStudy.MA,0) <= vMA2.getValue(MAStudy.MA,0) && vMA1.getValue(MAStudy.MA,-1) >= vMA2.getValue(MAStudy.MA,-1)) {
Alert.addToList(getSymbol(), "Slow MA >= Fast MA", Color.black, Color.red);
Alert.playSound("bullet.wav");
}
}
return new Array (vMA1.getValue(MAStudy.MA),vMA2.getValue(MAStudy.M A));
}
/************************************************** *******
Alexis C. Montenegro © July 2003
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
Modified basicmax3(alerts).efs 2009 to use only 2 MAs and be listed on Alert List
1/31/12 Modified to add color, style, and make alerts real-time
************************************************** ********/
var vMA1 = null;
var vMA2 = null;
var bInit = false;
function preMain() {
setPriceStudy(true);
setStudyTitle("Alert2MaxOver3");
setShowTitleParameters(false);
setCursorLabelName("Fast MA", 0);
setCursorLabelName("Slow MA", 1);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
var fp1 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
fp1.setName("Fast MA");
fp1.setLowerLimit(1);
fp1.setDefault(13); //Edit this value to set a new default
var fp2 = new FunctionParameter("MA1Offset", FunctionParameter.NUMBER);
fp2.setName("Fast MA Offset");
fp2.setDefault(0); //Edit this value to set a new default
var fp3 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
fp3.setName("Fast MA Source");
fp3.addOption("Close");
fp3.addOption("High");
fp3.addOption("Low");
fp3.addOption("Open");
fp3.addOption("HL/2");
fp3.addOption("HLC/3");
fp3.addOption("OHLC/4");
fp3.setDefault("Close"); //Edit this value to set a new default
var fp4 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
fp4.setName("Fast MAType");
fp4.addOption("MAStudy.SIMPLE");
fp4.addOption("MAStudy.EXPONENTIAL");
fp4.addOption("MAStudy.WEIGHTED");
fp4.addOption("MAStudy.VOLUMEWEIGHTED");
fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp5 = new FunctionParameter("Color1", FunctionParameter.COLOR);
fp5.setName("LFast MA Line Color");
fp5.setDefault(Color.red);
var fp6 = new FunctionParameter("Style1", FunctionParameter.STRING);
fp6.setName("Fast MA Style");
fp6.addOption("PS_SOLID");
fp6.addOption("PS_DASH");
fp6.addOption("PS_DOT");
fp6.setDefault("PS_SOLID");
var fp7 = new FunctionParameter("MA2Length", FunctionParameter.NUMBER);
fp7.setName("Slow MA");
fp7.setLowerLimit(1);
fp7.setDefault(50); //Edit this value to set a new default
var fp8 = new FunctionParameter("MA2Offset", FunctionParameter.NUMBER);
fp8.setName("Slow MA Offset");
fp8.setDefault(0); //Edit this value to set a new default
var fp9 = new FunctionParameter("MA2Source", FunctionParameter.STRING);
fp9.setName("Slow MA Source");
fp9.addOption("Close");
fp9.addOption("High");
fp9.addOption("Low");
fp9.addOption("Open");
fp9.addOption("HL/2");
fp9.addOption("HLC/3");
fp9.addOption("OHLC/4");
fp9.setDefault("Close"); //Edit this value to set a new default
var fp10 = new FunctionParameter("MA2Type", FunctionParameter.STRING);
fp10.setName("Slow MA Type");
fp10.addOption("MAStudy.SIMPLE");
fp10.addOption("MAStudy.EXPONENTIAL");
fp10.addOption("MAStudy.WEIGHTED");
fp10.addOption("MAStudy.VOLUMEWEIGHTED");
fp10.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp11 = new FunctionParameter("Color2", FunctionParameter.COLOR);
fp11.setName("Slow MA Line Color");
fp11.setDefault(Color.blue);
var fp12 = new FunctionParameter("Style2", FunctionParameter.STRING);
fp12.setName("Slow MA Style");
fp12.addOption("PS_SOLID");
fp12.addOption("PS_DASH");
fp12.addOption("PS_DOT");
fp12.setDefault("PS_SOLID");
}
function main(MA1Length,MA1Offset,MA1Source,MA1Type,Color1, Style1,MA2Length,MA2Offset,MA2Source,MA2Type,Color 2,Style2) {
if(bInit == false){
setDefaultBarFgColor(Color1,0);
setDefaultBarFgColor(Color2,1);
setDefaultBarStyle(eval(Style1),0);
setDefaultBarStyle(eval(Style2),1);
bInit = true;
}
if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Offset, MA1Source, eval(MA1Type));
if (vMA2 == null) vMA2 = new MAStudy(MA2Length, MA2Offset, MA2Source, eval(MA2Type));
if(getBarState()==BARSTATE_NEWBAR){
if(vMA1.getValue(MAStudy.MA,0) >= vMA2.getValue(MAStudy.MA,0) && vMA1.getValue(MAStudy.MA,-1) <= vMA2.getValue(MAStudy.MA,-1)) {
Alert.addToList(getSymbol(), "Fast MA >= Slow MA", Color.black, Color.green);
Alert.playSound("ding.wav");
}
if(vMA1.getValue(MAStudy.MA,0) <= vMA2.getValue(MAStudy.MA,0) && vMA1.getValue(MAStudy.MA,-1) >= vMA2.getValue(MAStudy.MA,-1)) {
Alert.addToList(getSymbol(), "Slow MA >= Fast MA", Color.black, Color.red);
Alert.playSound("bullet.wav");
}
}
return new Array (vMA1.getValue(MAStudy.MA),vMA2.getValue(MAStudy.M A));
}
Comment