Announcement

Collapse
No announcement yet.

Alert: EMA crosses DMA...how can I do that?

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

  • Alert: EMA crosses DMA...how can I do that?

    I am trying to create an Alert that shows me the crossover of one or two EMAs with a DMA. Can anybody help me. I have searched the entire Database for similar files. Can only find crossovers of Close/MA.

    Thanks

  • #2
    muecke
    If you run a Search for MA AND alert* you should find several examples of alerts on moving averages (even using more than two averages).
    Anyhow click here and you will find an example of real time alerts using two averages. Click instead here and you will find an example of alerts that are triggered only at the completion of a bar.
    Alex

    Comment


    • #3
      Thanks Alexis,

      was very useful.

      Now, how could I integrate a "PopUp-Alert" in this study?

      Looks like a lot of work, si puo farlo? Grazie in anticipo...

      Saluti

      Comment


      • #4
        muecke
        Certo che si puo fare. Enclosed below is an example for the one in real time
        Keep in mind that this script would be considerably simpler if you set the alerts to be triggered only at the completion of the bar or only once per bar irrespective of whether the averages will be crossed at the end of the period.
        Alex

        PHP Code:
        var vMA1 = new MAStudy(10"Close" MAStudy.SIMPLE);
        var 
        vMA2 = new MAStudy(50"Close" MAStudy.SIMPLE);

        function 
        preMain() {
            
        setPriceStudy(true);
            
        setStudyTitle("MAx2(one alert)");
            
        setCursorLabelName("MA1"0);
            
        setCursorLabelName("MA2"1);
            
        setDefaultBarFgColor(Color.blue0);
            
        setDefaultBarFgColor(Color.red1);  
        }

        var 
        vFlag1 0;
        var 
        vFlag2 0;

        function 
        main() {

            
        //this section determines the relative position of the averages at the prior bar
            //and sets the Flags accordingly
            
        if(getBarState() == BARSTATE_NEWBAR){
                if(
        vMA1.getValue(MAStudy.MA,-1) > vMA2.getValue(MAStudy.MA,-1)){
                    
        vFlag1 1;
                    
        vFlag2 1;
                    }    
                if(
        vMA1.getValue(MAStudy.MA,-1) < vMA2.getValue(MAStudy.MA,-1)){
                    
        vFlag1 = -1;
                    
        vFlag2 = -1;
                }
            }    
            
            
        //the following section triggers alerts only in the direction determined by the code above
            
            //if crossing over
            
        if(vFlag1 == -1){
                if(
        vMA1.getValue(MAStudy.MA) > vMA2.getValue(MAStudy.MA) && vFlag2 == -1){
                    
        Alert.playSound("ding.wav");
                    
        Alert.addToList(getSymbol()+"  "+getInterval(),"Crossing Up",Color.black,Color.blue);
                    
        vFlag2 1;
                }
                if(
        vMA1.getValue(MAStudy.MA) < vMA2.getValue(MAStudy.MA) && vFlag2 == 1){
                    
        vFlag2 = -1;
                }
            }
            
        //if crossing under
            
        if(vFlag1 == 1){
                if(
        vMA1.getValue(MAStudy.MA) < vMA2.getValue(MAStudy.MA) && vFlag2 == 1){
                    
        Alert.playSound("buzz.wav");
                    
        Alert.addToList(getSymbol()+"  "+getInterval(),"Crossing Down",Color.black,Color.red);
                    
        vFlag2 = -1;
                }
                if(
        vMA1.getValue(MAStudy.MA) > vMA2.getValue(MAStudy.MA) && vFlag2 == -1){
                    
        vFlag2 1;
                }
            }

          
            return new Array (
        vMA1.getValue(MAStudy.MA),vMA2.getValue(MAStudy.MA)); 

        Comment

        Working...
        X