Problem: Looping Alert!

 
#property copyright "FrostBite"
#property link      "orbilloalvin157@gmail.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input bool alert_sound=true;//Sound Alert
input bool alert_screen=true;//Screen Alert


int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {getHammerSignal();}

//+---------------------------------------------------------------------------------HAMMER CODE --------------------+
 int getHammerSignal(){
//+-----------------------------------------------------------------------------------------------------------------+
 
 datetime time1 = iTime(_Symbol,PERIOD_CURRENT,1);
 
    double high1 = iHigh(_Symbol,PERIOD_CURRENT,1);
    double low1 = iLow(_Symbol,PERIOD_CURRENT,1);
    double open1 = iOpen(_Symbol,PERIOD_CURRENT,1);
    double close1 = iClose(_Symbol,PERIOD_CURRENT,1);
 
    double high2 = iHigh(_Symbol,PERIOD_CURRENT,2);
    double low2= iLow(_Symbol,PERIOD_CURRENT,2);
    double open2 = iOpen(_Symbol,PERIOD_CURRENT,2);
    double close2 = iClose(_Symbol,PERIOD_CURRENT,2);
    
    double high3 = iHigh(_Symbol,PERIOD_CURRENT,3);
    double low3= iLow(_Symbol,PERIOD_CURRENT,3);
    double open3 = iOpen(_Symbol,PERIOD_CURRENT,3);
    double close3 = iClose(_Symbol,PERIOD_CURRENT,3);
              
double range1 = high1 - low1;
double range2 = high2 - high2;

///////////////////////////////////////////////////////////////////////////////////// FOR GREEN HAMMER LONG WICK BELOW
  if (open1 < close1 && close2 < open2 && open3 > close3){ 
      if(high1-close1 < range1 * 0.1 ){
         if(open1-low1  > range1 * 0.5 ){
            createObj(time1,low1,159,-1,clrYellow,"    bully",270,ALIGN_CENTER);
                   if(alert_sound)  {PlaySound("Alert.wav");}    
                   if(alert_screen){Alert("bully candle has been created.");}
             
      

            return 1;
         }
         }
         }
  
///////////////////////////////////////////////////////////////////////////////////// FOR GREEN HAMMER LONG WICK ABOVE
  if (open1 < close1 && close2 > open2){ 
      if(high1-close1 > range1 * 0.5 ){
         if(open1-low1  < range1 * 0.1 ){
            createObj(time1,low1,159,-1,clrRed,"    bear",270, ALIGN_CENTER);
                   if(alert_sound)  {PlaySound("Alert.wav");}    
                   if(alert_screen){Alert("bear candle has been created.");}                    
            return 1;
         }
         }
         }
         
         
         
   if (open1 > close1 && close2 > open2){ 
      if(high1-close1 > range1 * 0.5 ){
         if(open1-low1  < range1 * 0.3 ){
            createObj(time1,low1,159,-1,clrViolet,"    bear",270, ALIGN_CENTER);
                    if(alert_sound)  {PlaySound("Alert.wav");}    
                    if(alert_screen){Alert("bear candle has been created.");}
             


            return 1;
         }
         }
         }
                
/////////////////////////////////////////////////////////////////////////////////////////// RED HAMMER LONG WICK BELOW
   if (open1 > close1 && close2 < open2){ 
      if(high1-open1 < range1 * 0.1 ){
         if(close1-low1  > range1 * 0.5 ){
            createObj(time1,low1,159,-1,clrYellow,"      FvG Fill",270, ALIGN_CENTER);
                   if(alert_sound)  {PlaySound("Alert.wav");}    
                   if(alert_screen){Alert("FvG candle has been created.");}
            return 1;
         }
         }
         }
         
 ////////////////////////////////////////////////////////////////////////////////////////////////////////RED HANGINGMAN
   if (open1 > close1 && close2 > open2 && open3 < close3){ 
      if(high1-open1 < range1 * 0.1 ){
         if(close1-low1  > range1 * 0.2 ){
            createObj(time1,low1,159,-1,clrRed,"    HangMan",270, ALIGN_CENTER);
                   if(alert_sound)  {PlaySound("Alert.wav");}    
                   if(alert_screen){Alert("HangMan has been created.");}
            return 1;
         }
         }
         }
         
 ////////////////////////////////////////////////////////////////////////////////////////////////////////BEAR ENGULFING
   if (open1 > close1 && close2 > open2){ 
      if(high1-open1 < range1 * 0.1 ){
         if(close1-low1  > range1 * 0.2 ){
           if(open1 < close2 && close1 < open2){
              if(range1 / range2 >= 2  )
            createObj(time1,low1,159,-1,clrPink,"    pointBreak",270, ALIGN_CENTER);
                   if(alert_sound)  {PlaySound("Alert.wav");}    
                   if(alert_screen){Alert("pointbreak has been created.");}
            return 1;
         }
         }
         }
         }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////RED TWISTER
   if (open1 > close1 && close2 > open2 && open1 > close2 && close1 > close2 && low1 > low2){ 
      if(open1 - close1 < range1 * 0.5 ){
         if(high1 - open1 < range1 * 0.1 ){
            if(close1 - low1 > range1 * 0.6 ){
         createObj(time1,low1,159,-1,clrRed,"    REDspin",270, ALIGN_CENTER);
                   if(alert_sound)  {PlaySound("Alert.wav");}    
                   if(alert_screen){Alert("redSpin has been created.");}
            return 1;
         }
         }
         }
         }
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////         
return 0;
 }

   
void createObj(datetime time, double price, int arrowcode,int direction, color clr, string txt, int angle, const ENUM_ALIGN_MODE alignment){

string objName = "";
         StringConcatenate(objName,"Signal@", time, "at", DoubleToString(price, _Digits), "(",arrowcode,")");
         if(ObjectCreate(0,objName,OBJ_ARROW,0,time,price)){
         ObjectSetInteger(0,objName,OBJPROP_ARROWCODE,arrowcode);
         ObjectSetInteger(0,objName,OBJPROP_COLOR,clr);

            }
     
string objNameDesc = objName+txt;
      if(ObjectCreate(0,objNameDesc,OBJ_TEXT,0,time,price)){
         ObjectSetString(0,objNameDesc,OBJPROP_TEXT,"" +txt);
         ObjectSetInteger(0,objNameDesc,OBJPROP_COLOR,clr);
         ObjectSetDouble(0,objNameDesc,OBJPROP_ANGLE,270);
         ObjectSetInteger(0, objNameDesc, OBJPROP_ALIGN, alignment);
                  
      if(direction > 0) ObjectSetInteger(0,objNameDesc, OBJPROP_ANCHOR, ANCHOR_TOP);
      if(direction < 0) ObjectSetInteger(0,objNameDesc, OBJPROP_ANCHOR, ANCHOR_BOTTOM);
         
  }
  }
 
pLEASE! helpppp!!! I ONLY WANT the alert to alert [once]. And, stops when I close the pop up window. What to do?
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
orbilloalvin157 #:
pLEASE! helpppp!!! I ONLY WANT the alert to alert [once]. And, stops when I close the pop up window. What to do?

You code is executing at each tick, that's why the alert keep popping up.
You can simply make the code execute once per bar. and your issue will be resolved

 

Hi

As it was mentioned above simply perform function at the end of the bar, not every tick. You can use a function to detect if there is a new bar and call your function only then. For example:

void OnTick(){
        if(isnewbar()){
                getHammerSignal();
}
}
bool isnewbar(){
        static datetime prevbartime = 0;
        if(prevbartime !=  iTime(_Symbol, PERIOD_CURRENT, 0)){
                prevbartime = iTime(_Symbol, PERIOD_CURRENT, 0);
                return(true);
        }
        return(false);
}

Have a nice weekend👍📊