how to edit this simple indicator ?

 

hello every one

is there any way to edit this trend line by angle to give its alert ONLY when the Bid price equals its corresponding point on the line, as it givs an alert with every price tick even if it's far away from the line.

thanks in advanse

#property indicator_chart_window
extern string TLineName="MyLine2";
extern color LineColor=Red;
extern int LineStyle=STYLE_SOLID;
extern string AlertWav="alert.wav";
extern double Angle=45;
extern double Price1=00000;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
      ObjectCreate(TLineName, OBJ_TRENDBYANGLE, 0, Time[5], Price1, Time[1], Ask);
      ObjectSet(TLineName, OBJPROP_ANGLE, Angle);

      double val=ObjectGetValueByShift(TLineName, 0);
      if (Bid == val) PlaySound(AlertWav);{
       PlaySound(AlertWav);
       SendMail("TLine Alert","T Line Alert Pip Range");
       SendNotification("T LIne Alert Pip Range");
      } 

//----
//----
   return(0);
  }
 
ahm_zoz: as it givs an alert with every price tick
Of course it does.
Your code
if (Bid == val) PlaySound(AlertWav);{
   PlaySound(AlertWav);
   SendMail("TLine Alert","T Line Alert Pip Range");
   SendNotification("T LIne Alert Pip Range");
}
Same as
if (Bid == val) PlaySound(AlertWav);
{
PlaySound(AlertWav);
SendMail("TLine Alert","T Line Alert Pip Range");
SendNotification("T LIne Alert Pip Range");
}
Same as
if (Bid == val) PlaySound(AlertWav);
PlaySound(AlertWav);
SendMail("TLine Alert","T Line Alert Pip Range");
SendNotification("T LIne Alert Pip Range");
Fix your if/braces and then read The == operand. - MQL4 forum
 
WHRoeder:
Of course it does.
Your code
Same as
Same as
Fix your if/braces and then read The == operand. - MQL4 forum

........ . . ..............................................................................................................................................................................
thnx for ur replay

I don't understand what you mean exactly in the 3 cases with changing the braces {} but i guess you mean the equation should be some thing like

double val=ObjectGetValueByShift(TLineName, 0);
      if (Bid-AlertPipRange*Point <= val && Bid+AlertPipRange*Point >= val) PlaySound(AlertWav);{
       PlaySound(AlertWav);
       SendMail("TLine Alert","T Line Alert Pip Range");
       SendNotification("T LIne Alert Pip Range");
      } 

am I right or not??

thanks again

 
ahm_zoz: am I right or not??
Not. Your problem is the braces are not part of the IF.
 
WHRoeder:
Not. Your problem is the braces are not part of the IF.


I'm sorry mr.William, I have tried many ways but I can't find any soution :( .. even this

double val=ObjectGetValueByShift(TLineName, 0);
      if (Bid== val)
      {
       PlaySound(AlertWav);
       SendMail("TLine Alert","T Line Alert Pip Range");
       SendNotification("T LIne Alert Pip Range");
      }
 

You're almost there. Presumably with the last code you are not getting any alerts at all, rather than every tick?

If that is the case then you should mention this when reporting back, so that people know that your issue has changed then check the previously posted advice below:

There is a lot to read, you have to use a tolerance when comparing doubles ( Bid with val ) ....

WHRoeder:
Fix your if/braces and then read The == operand. - MQL4 forum

 
ydrol:

You're almost there. Presumably with the last code you are not getting any alerts at all, rather than every tick?

If that is the case then you should mention this when reporting back, so that people know that your issue has changed then check the previously posted advice below:

There is a lot to read, you have to use a tolerance when comparing doubles ( Bid with val ) ....



thank you

I think that every thing before and after (Bid== val) is true, but (Bid== val) itself is impossible !

Reason: