Announcement

Collapse
No announcement yet.

EMA Crossover Alert For James Coffey

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • EMA Crossover Alert For James Coffey

    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));

    }

  • #2
    SteveS
    Yes it is possible. To do that you would need to implement the following changes
    Add the following lines at the end of the preMain function

    PHP Code:
    var fp13 = new FunctionParameter("alertType"FunctionParameter.STRING);
        
    fp13.setName("Type of alert");
        
    fp13.addOption("Sound");
        
    fp13.addOption("Popup");
        
    fp13.addOption("Both");
        
    fp13.addOption("None");
        
    fp13.setDefault("Both"); //Edit this value to set a new default
        
        
    var fp14 = new FunctionParameter("alertSound"FunctionParameter.STRING);
        
    fp14.setName("Sounds");
        
    fp14.addOption("buzz.wav");
        
    fp14.addOption("ding.wav");
        
    fp14.addOption("beep.wav");
        
    fp14.addOption("blip.wav");
        
    fp14.addOption("chord.wav");
        
    fp14.setDefault("ding.wav"); //Edit this value to set a new default 
    Then replace the following line of code

    PHP Code:
    function main(MA1Length,MA1Offset,MA1Source,MA1Type,Color1Style1,MA2Length,MA2Offset,MA2Source,MA2Type,Color2,Style2) { 
    with the following

    PHP Code:
     function main (MA1LengthMA1OffsetMA1SourceMA1TypeColor1Style1MA2LengthMA2OffsetMA2SourceMA2TypeColor2Style2alertTypealertSound) { 
    Lastly replace the following section of code

    PHP Code:
    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.blackColor.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.blackColor.red); 
    Alert.playSound("bullet.wav");
    }

    with the following

    PHP Code:
    if (getBarState() == BARSTATE_NEWBAR) {
            if (
    vMA1.getValue(MAStudy.MA0) >= vMA2.getValue(MAStudy.MA0) && vMA1.getValue(MAStudy.MA, -1) <= vMA2.getValue(MAStudy.MA, -1)) {
                if(
    alertType!="None"){
                    if(
    alertType=="Both" ||alertType=="Popup"){
                        
    Alert.addToList(getSymbol(), "Fast MA >= Slow MA"Color.blackColor.green);
                    }
                    if(
    alertType=="Both"||alertType=="Sound"){
                        
    Alert.playSound(alertSound);
                    }
                }
            }
            if (
    vMA1.getValue(MAStudy.MA0) <= vMA2.getValue(MAStudy.MA0) && vMA1.getValue(MAStudy.MA, -1) >= vMA2.getValue(MAStudy.MA, -1)) {
                if(
    alertType!="None"){
                    if(
    alertType=="Both" ||alertType=="Popup"){
                        
    Alert.addToList(getSymbol(), "Fast MA >= Slow MA"Color.blackColor.green);
                    }
                    if(
    alertType=="Both"||alertType=="Sound"){
                        
    Alert.playSound(alertSound);
                    }
                }
            }
        } 
    Once you apply these changes you will be able to select whether to only trigger a popup or play a sound or both or neither. You will also be able to select between different sounds (note that you can always add more option to the appropriate function parameter
    Alex



    Originally posted by SteveS View Post
    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));

    }

    Comment

    Working...
    X