Announcement

Collapse
No announcement yet.

EMA alert

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

  • EMA alert

    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==&& !bEMAAlert0) {   
                
    Alert.addToList(thisSymbolthisInterval+" :EMA is touched"Color.blackColor.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(070EMAButton0Text+"@URL=EFS:EMAButton0CallBack"
            
    Color.blackEMAButton0Color
            
    Text.RELATIVETOTOP Text.RELATIVETOLEFT Text.LEFT Text.FRAME Text.ONTOP Text.BOLDnull10
            
    "EMAButton0");
        return;


  • #2
    Hello Richard,

    You are very close. You are properly setting your control flag to true the first time your alert condition is true. The problem is that during the same interval, the first occurence where your alert condition then evaluates back to false, your else statement gets executed and resets your control flag back to false. The next trade that occurs after that where your alert condition evaluates to true again also executes your alert again because the control variable was reset to false.

    What you need to do is only reset the control variable back to false at BARSTATE_NEWBAR. That way, your alert will only execute the first time the alert condition evaluates to true for the duration of that bar. Try the modified code below. Also notice that I removed the else statement where you were previously allowing the control variable to get reset during the bar.


    PHP Code:
    function main()
    {   
        
    dThisEMA ema(nEMALength);
        
        
    RichButtons();
        
        if( 
    getBarState() == BARSTATE_ALLBARS ) {
            
    thisInterval getInterval();
            
    thisSymbol getSymbol();
        }
        
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    bEMAAlert0 false;
        }
        
        if ( 
    high()>=dThisEMA && low()<=dThisEMA ) {
            if (
    EMAAlert0Mode==&& !bEMAAlert0) {   
                
    Alert.addToList(thisSymbolthisInterval+" :EMA is touched"Color.blackColor.purple);
                
    Alert.playSound(EMAAlert0Sound);
            }
            
    bEMAAlert0 true;
        }
       
        return;
        

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      I hv below EMAs on a 10min chart for NQ#F with time template of 9:30-16:15.

      v0 = ema(20);
      v1 = ema(20, inv(60));
      v2 = ema(20, inv(240));

      However, the system keeps on sending alerts out telling me that the 240min 20-EMA has been touched. Any advice?

      Comment


      • #4
        Hello Richard,

        Without seeing the code you're using it's difficult to provide any guidance. Please post your formula as an attachment and I'll take a look.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          pls see the attached file. thx.
          Attached Files

          Comment


          • #6
            Hello Richard,

            Thank your for posting your code, which was also nice and tidy. Much appreciated. I think the problem is on line 114.

            PHP Code:
            if (EMAAlert3Mode==&& MuteAllMode==&& !bEMAAlert1) { 
            bEMAAlert1 should be bEMAAlert3
            PHP Code:
            if (EMAAlert3Mode==&& MuteAllMode==&& !bEMAAlert3) { 
            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              thank you. So I hv made a stupid mistake...

              Comment

              Working...
              X