alarm indicator , help please..

 

i like to ask your advices about an Alarm indicator or EA, please... actuallay it is not for me, but for a trader friend of mine.. he asked my help and i promised to help him indeed..

1) i need a kind of alarm indicator/EA .. it will recognize manually drawn trendlines and it will alarm if the price hits the trend line.. is it possible ? and can i find such any indikator or EA ?

2) or, i need help to repair an existing EA, please.. it is in the attachement.. my friend has an Alarm EA already but it needs some repair.. it has a problem, my friend says.. it alerts with every trendline, in sense of, not just with the last manually drawn trendline but also it alerts with other trendlines which has drawn before.. so it fails.. can anybody repair it ? or better, any advice for such EA please..


thanks a lot and regards..

Files:
 

Hello, could be done.

If you show us some code YOU made we would help you with the problems you have.

I hope you understand that this forum is not only giving, but helping

 

Ok, lets examin your code:

#property indicator_chart_window


double SoundWhenPriceIsExactly = 0;
extern bool Alarm=true;
extern bool SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT4. E-mail SMTP Server settings should also be configured in your MT4
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init() 
{
 return;
  int    obj_total=ObjectsTotal();
  string name;
  for(int i=0;i<obj_total;i++)
    {

     name=ObjectName(i);
     ObjectDelete(name);
     }
   return(0);
}


int start()
{

  int    obj_total=ObjectsTotal();
  string name;
  for(int i=0;i<obj_total;i++)
    {
          double price=0;
           name=ObjectName(i);
           if(name!="") price = ObjectGet(name, OBJPROP_PRICE1);  // you are taking PRICE1 as price, with a trendline you need to use https://docs.mql4.com/objects/ObjectGetValueByShift
                          SoundWhenPriceIsExactly = NormalizeDouble(price, Digits); 
//           Print(name," ",i," ",obj_total);

     if ((Bid == SoundWhenPriceIsExactly) || (Ask == SoundWhenPriceIsExactly) && SoundWhenPriceIsExactly>0) //Comparing doubles never works reliable
       {
       Alert(Symbol()," Belirlenen Fiyat Deðerine Ulaþtý. "+ DoubleToStr(Ask,Digits));
       PlaySound("alert.wav");
       SendMail(Symbol()," Belirlenen Fiyat Deðerine Ulaþtý.."+ DoubleToStr(Ask,Digits));
       if(name!="") ObjectDelete(name);
       SoundWhenPriceIsExactly = 0;
       }
     }


}
 

Use something like this to find the last trendline:

String lastTL="";
datetime lastTLtime=0;
for(int i=0;i<ObjectsTotal();i++){
  String tmp=ObjectName(i);
  if(ObjectType(tmp)==OBJ_TREND){
    if(ObjectGet(tmp,OBJPROP_TIME2)>lastTLtime){
     lastTL=tmp;
     lastTLtime=ObjectGet(tmp,OBJPROP_TIME2);
    }
  }
}

and something like this to compare:

static double ask.old=0;
static double bid.old=0;

if(ask.old!=0 && bid.old!=0){
  if((ask.old<tlPrice && Ask>tlPrice) || (bid.old<tlPrice && Bid>tlPrice) || (ask.old>tlPrice && Ask<tlPrice) || (bid.old>tlPrice && Bid<tlPrice)){
    //ALERT TOUCH HAPPEND
  }
}
ask.old=Ask;
bid.old=Bid;
 

dear zzuegg,

thanks a lot for your time and kind helps..

actually i am very new at forum and to tell the truth, i have very short info and experience in metatrader skills.. im here for a friend really.. because he cant speak english..

thanks a lot for your help, i will follow your advices actually..

i have programming skills, and i can understand the code mostly.. but i cant be sure, how can i apply your adds in the code ? can you help please ?

thanks a lot and regards..

Reason: