Announcement

Collapse
No announcement yet.

MAX Email

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

  • MAX Email

    Hello;
    Is it possible to have Esignal email me when a certain stock crosses 2 Moving Averages?
    I looked at the alert function of Esignal but that didn't help with MA cross over.
    Thanks for your time....Greg

  • #2
    Re: MAX Email

    Greg
    It is possible by defining the appropriate condition and using the Alert.email() function (for the complete syntax of the alert function see the link to the article in the EFS KnowledgeBase)
    Having said that the description you provide does not clearly define what this condition would be and because there are several possible scenarios the logic required could be quite different in each case.
    For example would price have to cross one average when this is already above or below the other one? In this case the condition could be written as follows
    PHP Code:
    var Condition1 Average1.getValue(-1)>Average2.getValue(-1) && 
                     
    Close.getValue(-1)>Average1.getValue(-1) && 
                     
    Close.getValue(-2)<Average1.getValue(-2);
    var 
    Condition2 Average1.getValue(-1)<Average2.getValue(-1) && 
                     
    Close.getValue(-1)<Average1.getValue(-1) &&
                     
    Close.getValue(-2)>Average1.getValue(-2);
     
    if(
    getBarState()==BARSTATE_NEWBAR){//at every first tick of a new bar
        
    if(Condition1){//if Condition1 is true
                
    Alert.email("Crossed over");//send email
        
    }
        if(
    Condition2){//if Condition2 is true 
                
    Alert.email("Crossed under");//send email
        
    }

    The alert gets triggered every time that at the completion of a bar price has crossed above or below Average1 and this is respectively above or below Average2. However price could have for example crossed above Average1 while this is still under Average2 in which case no alert would be triggered when price is then above both unless it crosses under and then back above Average1 while this is above Average2 (same for the reverse condition)
    Or does price have to cross above or below both averages regardless of where they are respect to each other? In this case the condition could be written as follows
    PHP Code:
    var Condition1 Close.getValue(-1)>Average1.getValue(-1) && 
                     
    Close.getValue(-1)>Average2.getValue(-1);
    var 
    Condition2 Close.getValue(-1)<Average1.getValue(-1) &&
                     
    Close.getValue(-1)<Average2.getValue(-1);
     
    if(
    getBarState()==BARSTATE_NEWBAR){
        if(
    Condition1){//if Condition1 is true
                
    if(LastAlert!=1Alert.email("Crossed over");//if LastAlert is not equal to 1 send email
                
    LastAlert 1;//set LastAlert to 1 to prevent further alerts
                //note LastAlert needs to be a global variable set initially to a value other than 1 or 2
        
    }
        if(
    Condition2){//if Condition2 is true
                
    if(LastAlert!=2Alert.email("Crossed under");//if LastAlert is not equal to 2 send email
                
    LastAlert 2;//set LastAlert to 2 (same reason as above)
        
    }

    The alert gets triggered the first time that at the completion of a bar price closes above or below both averages regardless of where they are respect to each other
    Or yet another scenario does price just have to be above or below the first average and this is respectively above or below the other one? In this case the code could be written as follows
    PHP Code:
    var Condition1 Avg1.getValue(-1)>Avg2.getValue(-1) && 
                     
    Close.getValue(-1)>Avg1.getValue(-1);
    var 
    Condition2 Avg1.getValue(-1)<Avg2.getValue(-1) && 
                     
    Close.getValue(-1)<Avg1.getValue(-1);
     
    if(
    getBarState()==BARSTATE_NEWBAR){
        if(
    Condition1){//if Condition1 is true
            
    if(LastAlert1!=1Alert.email("Crossed over");//if LastAlert1 is not equal to 1 send email
            
    LastAlert1 1;//set LastAlert1 to 1 to prevent further alerts
            //note LastAlert1 needs to be a global variable set initially to a value other than 1 or 2
        
    }
        if(!
    Condition1){//if Condition1 is false 
            
    LastAlert1 2;//set LastAlert1 to 2 to allow further alerts when Condition1 is true again
        
    }
        if(
    Condition2){//if Condition2 is true
            
    if(LastAlert2!=1Alert.email("Crossed under");//if LastAlert2 is not equal to 1 send email
            
    LastAlert2 1;//set LastAlert2 to 1 (same reason as above)
            //note LastAlert2 needs to be a global variable set initially to a value other than 1 or 2
        
    }
        if(!
    Condition2){//if Condition2 is false
            
    LastAlert2 2;//set LastAlert2 to 2 (same reason as above)
        
    }

    The alert gets triggered the first time of every instance in which at the completion of a bar price is above one average and this is above the other or price is below one average and this is below the other.
    Note that in all the above examples I am assuming the you have declared the variables Average1, Average2 and Close and assigned to them the appropriate functions [for example sma(10) or close(), etc] and also that you have declared the various flag LastAlert, LastAlert1, etc as indicated in the comments. FWIW the way these flags are used is the same as implemented by the Formula Wizard
    As you can see there are many possible scenarios involved each with its own logic and coding routines.
    Anyhow you should now have enough examples to be able to write your own code based on your specific requirements
    Also run a search in the forum for average* AND alert* and you will find many other examples
    Alex


    Originally posted by gwika
    Hello;
    Is it possible to have Esignal email me when a certain stock crosses 2 Moving Averages?
    I looked at the alert function of Esignal but that didn't help with MA cross over.
    Thanks for your time....Greg

    Comment


    • #3
      MAX Email

      Alex;
      Thanks for the great email and answering so quickly. Is it possible to have an alert when one MA crosses the other MA? (50MA crossing the 200MA)
      I hope you and everyone else at Esignal have a Very Merry Christmas.
      Greg

      Comment


      • #4
        Re: MAX Email

        Greg
        Yes it is possible. As I suggested in my previous reply run a search for average* AND alert* and you will find many examples of alerts triggered by crossing of averages as this topic has been covered extensively.
        A Merry Christmas to you too.
        Alex


        Originally posted by gwika
        Alex;
        Thanks for the great email and answering so quickly. Is it possible to have an alert when one MA crosses the other MA? (50MA crossing the 200MA)
        I hope you and everyone else at Esignal have a Very Merry Christmas.
        Greg

        Comment

        Working...
        X