Download MetaTrader 5

Strange alert problem

To add comments, please log in or register
smika
131
smika  

Hi,

 

I try to learn some coding. I try to make a TDI indicator with different alerts. Als I want that those alerts only will be send and the beginning of a new candle.

When for example there is an TDI crossover red over green (scalping alert) I got an alert and everything works fine.

But when I have another chart with the same  indicator but on this chart I've got an crossover red over green alert (scalping alert) AND another alert for example green over red and yellow (active alert) (seperate alerts) then the alert repeats itself over and over again. 

So when a chart has only 1 alert, it doesn't repeat. 

//mail settings
datetime now;
bool alerted = false;

if (IsNewBar()) alerted = false;
  if (!alerted)
        
       if (Scalping_Alert)
       {
         int whichBar=1;
         if (alertsOnCurrent) whichBar = 0;
        
          if (!Gyppy_3_over_15_filter)
        
                  
         if (MaBuf[whichBar]>MbBuf[whichBar]&& MaBuf[whichBar+1]<MbBuf[whichBar+1])
            {
            
            doAlert(whichBar,"Scalping Alert Long");
            }
         if (MaBuf[whichBar]<MbBuf[whichBar]&& MaBuf[whichBar+1]>MbBuf[whichBar+1])
            {
            doAlert(whichBar,"Scalping Alert Short");
            }  
                
                          
          if (Gyppy_3_over_15_filter)
        
                  
        if (MaBuf[whichBar]>MbBuf[whichBar]&&(ema3>ema15) && MaBuf[whichBar+1]<MbBuf[whichBar+1])
            {
            doAlert(whichBar,"Scalping Alert Long");
            }
         if (MaBuf[whichBar]<MbBuf[whichBar]&&(ema3<ema15) && MaBuf[whichBar+1]>MbBuf[whichBar+1])
            {
            doAlert(whichBar,"Scalping Alert Short");
            }
                              
       }
      
       if (Active_Alert)
       {
         int whichBar=1;
         if (alertsOnCurrent) whichBar = 0;
        
          if (!Gyppy_3_over_15_filter)
        
        
         if (MaBuf[whichBar]>MbBuf[whichBar]&&MbBuf[whichBar]>MdZone[whichBar] && MaBuf[whichBar+1]<MbBuf[whichBar+1])
            {
            doAlert(whichBar,"Active Alert Long");
            }
         if (MaBuf[whichBar]<MbBuf[whichBar]&&MbBuf[whichBar]<MdZone[whichBar] && MaBuf[whichBar+1]>MbBuf[whichBar+1])
            {
            doAlert(whichBar,"Active Alert Short");
            }  
                        
        
          if (Gyppy_3_over_15_filter)
        
        
         if (MaBuf[whichBar]>MbBuf[whichBar]&&MbBuf[whichBar]>MdZone[whichBar]&&(ema3>ema15)  && MaBuf[whichBar+1]<MbBuf[whichBar+1])
            {
            doAlert(whichBar,"Active Alert Long");
            }
         if (MaBuf[whichBar]<MbBuf[whichBar]&&MbBuf[whichBar]<MdZone[whichBar]&&(ema3<ema15)  &&  MaBuf[whichBar+1]>MbBuf[whichBar+1])
            {
            doAlert(whichBar,"Active Alert Short");
            }
                              
       }        

       alerted = true;
return(rates_total);
}
Keith Watford
Moderator
10645
Keith Watford  

   bool alerted=false;              //alerted is set to false

   if(IsNewBar()) alerted=false;    //alerted is still set to false
   if(!alerted)                     //This will always be true

   alerted=true;                   //alerted is set to true, but next tick will be set to false again
   return(rates_total);
  }
.
whroeder1
15934
whroeder1  
Look at the new bar code. How does it remember the current bar? Why doesn't your alerted do the same?
To add comments, please log in or register