One Alert per signal not once every bar

 

Please there is difference between  one alert per signal and Alert once per bar.


Please any help on the code snippet for indicator to alert once per signal and not once per bar

if(iTime(Symbol(),0,0)!=0){


Alert();

iTime(Symbol(),0,0)=0;
}

This is for alert once per bar. What of Alert once if only the signal is true?

 

Once alert per bar can have only one alert per bar, and thus also only once alert per signal.

Where once alert per signal can have multiple alerts per bar, because there can be more then once signal in a bar.

You have to define signal every time, or signal oscillator, called flip/flop it's one alert for high then one alert for low and etc.

if(signal==1)
 {
  Alert();
  signal=0;
 }

else if(signal==0)
 {
  Alert();
  signal=1;
 }
 
if(iTime(Symbol(),0,0)!=0){     //Very strange as it will always !=0 unless there is no history loaded    


Alert();

iTime(Symbol(),0,0)=0;          //No idea what you are trying to do here. This will not compile.
}

 
gbenga Ayodele: Please any help on the code snippet for indicator to alert once per signal and not once per bar

Don't alert on a signal, alert on a change in signal

static bool  isSignal=true; bool wasSignal = isSignal;
isSignal = ...;
if(isSignal && !wasSignal) Alert(...);
 
whroeder1:

Don't alert on a signal, alert on a change in signal


Like there are some indicator that alert on cross which is easy to logically code.

i am having issue with some signal indicator not the one on

if(A cross B) Alert();

if i place it on M30 it alerts me every 30 minutes on the same signal.

it actually alerts once on every new bar formation.

int flagval1 = 0;
int flagval2 = 0;
 double tmp=0; 


for (shift = CountBars; shift>=0; shift--) 
   { 

         
      if (.....signal condition is true....)
      {
              if (shift == 1 && flagval1==0){  flagval1=1; flagval2=0; }
              val1[shift]=Low[shift]-5*Point;
      }
      if (....signal condition is true..............) 
      {
         if (shift == 1 && flagval2==0) { flagval2=1; flagval1=0; }
              val2[shift]=High[shift]+5*Point;
      }
   }
   if (flagval1==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_BUY)
   {
//      Print("Last Alert before BUY = ",GlobalVariableGet("LastAlert"+Symbol()+Period()));
//      if (GlobalVariableGet("LastAlert"+Symbol()+Period()) < 0.5)
//      {
        if (SoundON) Alert(TimeToStr(CurTime(),TIME_DATE), "   BUY    ",Symbol() , TFToStr(Period()),"   ",TimeHour(CurTime()),":",TimeMinute(CurTime()));
        if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
//      }
      tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
      GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
      GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELL);
//      GlobalVariableSet("LastAlert"+Symbol()+Period(),1);
   }
   
   if (flagval2==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period()) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_SELL)
    {
//      Print("Last Alert before SELL = ",GlobalVariableGet("LastAlert"+Symbol()+Period()));
//      if (GlobalVariableGet("LastAlert"+Symbol()+Period()) > -0.5)
//      {
        if (SoundON) Alert(TimeToStr(CurTime(),TIME_DATE), "   SELL    ",Symbol() , TFToStr(Period()),"   ",TimeHour(CurTime()),":",TimeMinute(CurTime()));
        if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
//      }
      tmp = CurTime() + (Period()-MathMod(Minute(),Period()))*60;
      GlobalVariableSet("AlertTime"+Symbol()+Period(),tmp);
      GlobalVariableSet("SignalType"+Symbol()+Period(),OP_BUY);
//      GlobalVariableSet("LastAlert"+Symbol()+Period(),-1);
   }
 
gbenga Ayodele:

Please there is difference between  one alert per signal and Alert once per bar.


Please any help on the code snippet for indicator to alert once per signal and not once per bar

This is for alert once per bar. What of Alert once if only the signal is true?


extern int     AlertCandle         = 1;                                                                                                         //
extern bool    ShowChartAlerts     = false;                                                                                                     //
extern string  AlertEmailSubject   = "";                                                                                                        //
                                                                                                                                                //
datetime       LastAlertTime       = -999999;                                                                                                   //
                                                                                                                                                //
string         AlertTextCrossUp    = "Sixths cross UP";                //---- type your desired text between the quotes                         //
string         AlertTextCrossDown  = "Sixths cross DOWN";              //---- type your desired text between the quotes                         //
                                                                                                                                                //
// ============================================================================================================================================ //

double   AlertPriceHigh, AlertPriceLow;
int      count = 1;


int ProcessAlerts()   {                                                                                                                         //
//+------------------------------------------------------------------+                                                                          //
  if (AlertCandle >= 0  &&  Time[0] > LastAlertTime)   {                                                                                        //
                                                                                                                                                //
    // === Alert processing for crossover UP (indicator line crosses ABOVE signal line) ===                                                     //
    if (Close[AlertCandle] > AlertPriceHigh  &&  Close[AlertCandle+1] <= AlertPriceHigh)  {                                                     //
      string AlertText = Symbol() + "," + TFToStr(Period()) + ": " + AlertTextCrossUp;                                                          //
      if (ShowChartAlerts)          Alert(AlertText);                                                                                           //
      if (AlertEmailSubject > "")   SendMail(AlertEmailSubject,AlertText);                                                                      //
      LastAlertTime = Time[0];                                                                                                                  //
    }                                                                                                                                           //
    if (Close[AlertCandle] > AlertPriceLow  &&  Close[AlertCandle+1] <= AlertPriceLow)  {                                                       //
      AlertText = Symbol() + "," + TFToStr(Period()) + ": " + AlertTextCrossUp;                                                                 //
      if (ShowChartAlerts)          Alert(AlertText);                                                                                           //
      if (AlertEmailSubject > "")   SendMail(AlertEmailSubject,AlertText);                                                                      //
      LastAlertTime = Time[0];                                                                                                                  //
    }                                                                                                                                           //
                                                                                                                                                //
    // === Alert processing for crossover DOWN (indicator line crosses BELOW signal line) ===                                                   //
    if (Close[AlertCandle] < AlertPriceHigh  &&  Close[AlertCandle+1] >= AlertPriceHigh)  {                                                     //
      AlertText = Symbol() + "," + TFToStr(Period()) + ": " + AlertTextCrossDown;                                                               //
      if (ShowChartAlerts)          Alert(AlertText);                                                                                           //
      if (AlertEmailSubject > "")   SendMail(AlertEmailSubject,AlertText);                                                                      //
      LastAlertTime = Time[0];                                                                                                                  //
    }                                                                                                                                           //
    if (Close[AlertCandle] < AlertPriceLow  &&  Close[AlertCandle+1] >= AlertPriceLow)  {                                                       //
      AlertText = Symbol() + "," + TFToStr(Period()) + ": " + AlertTextCrossDown;                                                               //
      if (ShowChartAlerts)          Alert(AlertText);                                                                                           //
      if (AlertEmailSubject > "")   SendMail(AlertEmailSubject,AlertText);                                                                      //
      LastAlertTime = Time[0];                                                                                                                  //
    }                                                                                                                                           //
                                                                                                                                                //
  }                                                                                                                                             //
  return(0);                                                                                                                                    //
}                                                                                                                                               //
      

Will this work ?

 
gbenga Ayodele:

Will this work ?


I tested the above it didn't work

Solution to this problem is still at large.........

 

I dont see a single else if in that code.

 
Marco vd Heijden:

I dont see a single else if in that code.


i now know where the problem is from

Signals and the corresponding alert must be defined separately

datetime previous =0;
for(int i =Bars-1; i>=0; i--){
double aa = iMA(..............................);
double bb = iMA(.............................);
 if(aa>bb){
Val1[i] = High[i]+5*Point;

to..Do here..;
  }
 if(aa<bb){
Val2[i] = Low[i]-5*Point;

to..Do here..;
}

if(Alerts){
for(i=i+1, i>=0; i--){
double aa = iMA(..............................);
double bb = iMA(.............................);
    
}// note the position of the end of the iteration for the alert
if(aa>bb){
if (previous Alert != Time[0]){

Alert();
SemdMail();
} //note the position of this also
previous = Time[0];
}

if(aa<bb){
if (previous Alert != Time[0]){

Alert();
SemdMail();
} //note the position of this also
previous = Time[0];
}

Will this work?


Most of us don't know much about this mql4 and now there is mql5 to deal with ahead.......

Reason: