Announcement

Collapse
No announcement yet.

EFS: alert and sound just once

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

  • EFS: alert and sound just once

    Hi folks,
    I would like to have the following efs to sound and display the alert just once price crosses the threshold.


    /************************************************** ***************
    Provided By : eSignal. (c) Copyright 2003
    ************************************************** ***************/

    function preMain() {
    setStudyTitle(" Tick Extremes ");
    setCursorLabelName("TICK C", 0);
    setPlotType(PLOTTYPE_LINE, 0);
    setStudyMax(1500);
    setStudyMin(-1500);
    }

    var vColor = Color.white;
    var vLoaded = false;

    function main(nTickHigh, nTickLow, nNumOfBars) {
    if (nTickHigh == null) nTickHigh = 1000;
    if (nTickLow == null) nTickLow = -1000;
    if (vLoaded == false) {
    addBand(nTickHigh, PS_SOLID, 1, Color.yellow, "top");
    addBand(0, PS_SOLID, 1, Color.grey, "zero");
    addBand(nTickLow, PS_SOLID, 1, Color.yellow, "bottom");
    vLoaded = true;
    }

    var c = close(0, 1, "$tick")*1;
    if (c == null) return;

    vColor = Color.white;

    if (c > nTickHigh) {
    vColor = Color.lime;
    Alert.playSound("ding.wav");
    Alert.addToList(getSymbol()+" "+getInterval(),"tick Up",Color.white,Color.lime);
    }
    if (c < nTickLow) {
    vColor = Color.red;
    Alert.playSound("ding.wav");
    Alert.addToList(getSymbol()+" "+getInterval(),"tick down",Color.white,Color.red);
    }

    setBarFgColor(vColor, 0);

    return c;
    }


    Please advice.

    Thanks,
    Matt

  • #2
    Matt
    First create a global variable called for example vFlag and set it equal to 0 (or false);
    Then in main reset that vFlag=0 (or false) at every new bar (ie inside a BARSTATE_NEWBAR statement).
    Then in the conditions that trigger the alert add a vFlag == 0 (or false) condition).
    Lastly after all the alert commands add vFlag = 1 (or true).
    All these steps will allow the alert to trigger only once per event
    Alex

    Comment


    • #3
      Hi Alex,

      thanks for the quick response.
      But that's way over my head.
      I am pretty good at cut and paste.
      So I cut the alert paragraph from one of the efs you helped me with before, and pasted it in this efs.
      It kind of worked except the constant alert.
      So if you have a free minute maybe you could "cut and paste" this flag etc command in this efs?

      Thanks again,

      Matt

      Comment


      • #4
        Matt
        The enclosed implements the changes I suggested. Comments are included in the script
        Alex

        PHP Code:
        function preMain() {
            
        setStudyTitle(" Tick Extremes ");
            
        setCursorLabelName("TICK C"0);
            
        setPlotType(PLOTTYPE_LINE0);
            
        setStudyMax(1500);
            
        setStudyMin(-1500);
        }

        var 
        vColor Color.white;
        var 
        vLoaded false;
        var 
        vFlag false;//global variable vFlag set to false

        function main(nTickHighnTickLownNumOfBars) { 

            if(
        getBarState()==BARSTATE_NEWBAR){//at every new bar
                
        vFlag false//reset vFlag to false
            
        }

            if (
        nTickHigh == nullnTickHigh 1000;
            if (
        nTickLow == nullnTickLow = -1000;
            
            if (
        vLoaded == false) {
                
        addBand(nTickHighPS_SOLID1Color.yellow"top");
                
        addBand(0PS_SOLID1Color.grey"zero");
                
        addBand(nTickLowPS_SOLID1Color.yellow"bottom");
                
        vLoaded true;
            }

            var 
        close(0"$tick");//modified
            
        if (== null) return;

            
        vColor Color.white;

            if (
        nTickHigh) {
                
        vColor Color.lime;
                if(
        vFlag == false){//nested condition to check vFlag
                    
        Alert.playSound("ding.wav");
                    
        Alert.addToList(getSymbol()+" "+getInterval(),"tick Up",Color.white,Color.lime);
                    
        vFlag true;//set vFlag to true
                
        }
            }

            if (
        nTickLow) {
                
        vColor Color.red;
                if(
        vFlag == false){//nested condition to check vFlag
                    
        Alert.playSound("ding.wav");
                    
        Alert.addToList(getSymbol()+" "+getInterval(),"tick down",Color.white,Color.red);
                    
        vFlag true;//set vFlag to true
                
        }
            }

            
        setBarFgColor(vColor0);

            return 
        c;

        Comment


        • #5
          GREAT!

          Thank you kindly Alex.

          Matt

          Comment


          • #6
            alert and sound just once

            Hello Alex,

            I'm having kind of the same problem with multiple alerts being triggered. As you can see in the attached MA efs, the study gets updated on real time, which is the way it should work, but then I get a lot of alerts. Is there any way to limit the alerts and keep the real time feature?

            Also, when an e-mail alert is sent, on the subject line I get the symbol and if crossed up or down. How can I just change it to just show "CROSSED UP" or "CROSSED DOWN" ?

            Thanks in advance for your help,
            Alejandro
            Attached Files

            Comment


            • #7
              Alejandro
              The efs does exactly what it was originally requested to do (see this thread) which is to trigger a single alert every time the averages cross in a given direction. This means that the alert will reset and trigger again if during the bar the averages uncross and cross again.
              Run a search for average* AND alert* and you should find several efs that will plot the averages in real time but will trigger the alerts only when the averages are crossed at the completion of the bar.
              Alex

              Comment

              Working...
              X