//+------------------------------------------------------------------+
//|                                            MTrendLine  alert.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
//|                                         MTrendLine  alert v2.mq4 |
//|                       ReDesign + Add "pip = ? $ | =? % Account"  |
//|                       + show Pips correct in broker digits number|    
//|                                   by Cmkm-2011- thhudu@yahoo.com | 
//+------------------------------------------------------------------+
#property copyright "Copyright Cmkm + MetaQuotes Software Corp."

#property indicator_chart_window

 extern int Alert_pips=3;
 extern bool _______________TrendLine_1 = true ; 
 extern bool _______________TrendLine_2 = false;
 extern bool ___Show_$ = true;
 extern double Lot=0;
 extern double Deposit=0;
 extern int  ___Clearance=55;
 extern color Line1=Lime;
 extern color Line2=Magenta;
 extern bool PopupON=false;
 
bool _______________TrendLine_3 = false ; 
bool _______________TrendLine_4 = false ; 
bool EmailON=false;
bool Sound_Alert=true;
string AlertSound="alert.wav";

bool normalize = true; //If true then the spread is normalized to traditional pips
double Poin;
int n_digits = 0;
double divider = 1;
//+----------------+
int init()
  { IndicatorShortName("MtrendLine_alert v2 | ");

   //Checking for unconvetional Point digits number
   if (Point == 0.00001) Poin = 0.0001; //5 digits
   else if (Point == 0.001) Poin = 0.01; //3 digits
   else Poin = Point; //Normal
   
   if ((Poin > Point) && (normalize))
   {  divider = 10.0;
      n_digits = 1;  }
   return(0);
}
//+----------------+
int deinit()
  {
     ObjectDelete("1"); ObjectDelete("2");ObjectDelete("3"); ObjectDelete("4");  
    // ObjectDelete("TrendLine 1"); ObjectDelete("TrendLine 2"); 
   //  ObjectDelete("TrendLine 3"); ObjectDelete("TrendLine 4");
   return(0);
  }
//+----------------+
string a$;
int start(){        datetime objtime = Time[0] + Period()*60*___Clearance;

//--------Lot-------
   double MinLot =MarketInfo(Symbol(), MODE_MINLOT);
   if (Lot<0.01){Lot=MinLot;}
   
//--------Pip-Lot-------
   double Pip_Lot=MarketInfo(Symbol(), MODE_TICKVALUE)/10;
   if (Lot<0.01){ Pip_Lot=Pip_Lot;}
     else{Pip_Lot=Pip_Lot*Lot/MinLot;} 
     
//--------Account Balance------- 
  if (Deposit==0){ Deposit = AccountBalance();}
      else{Deposit=Deposit;}
  
 //+------TrendLine_1-----------------------+
      int a=MathAbs((NormalizeDouble(Bid,Digits)-NormalizeDouble                             //pips
           (ObjectGetValueByShift("Trendline "+1,0),Digits))*MathPow(10,Digits)/divider);
           
      if (___Show_$ == true){ string a$=" p = "+DoubleToStr(a*Pip_Lot,1)+" $       |  "+
                                  DoubleToStr(NormalizeDouble(a*Pip_Lot,1)*100/Deposit,1)+" % Acc ";}    //Show $ & % Acc
      //+--
    if( _______________TrendLine_1==true){
      ObjectCreate("TrendLine 1", OBJ_TREND, 0, Time[12], Bid+35*Point , Time[0]+3600, Bid+35*Point );   //Create Trendline
      ObjectSet("TrendLine 1", OBJPROP_COLOR, Line1);                                           
    if    (ObjectFind("1")==-1){ ObjectCreate("1",OBJ_TEXT, 0, 0, 0); }                                  //Create text pips
      ObjectSetText("1",a+a$,9,"Arial",Line1); 
      ObjectSet("1",OBJPROP_PRICE1,NormalizeDouble(ObjectGetValueByShift("Trendline "+1,0),Digits)); 
             ObjectSet("1",OBJPROP_TIME1,objtime) ;  
      //+---      
           double val1=ObjectGetValueByShift("Trendline 1", 0);
      if (Bid-Alert_pips*Point <= val1 && Bid+Alert_pips*Point >= val1)
     {   if (Sound_Alert) PlaySound (AlertSound);
         if (PopupON) Alert (Symbol()," price within ",Alert_pips," pips of ","Trendline 1");
         if (EmailON) SendMail(Symbol()+" ",Alert_pips+" pips from "+"Trendline 1");  }
     }  else {ObjectDelete("TrendLine 1");}
     
 //+------TrendLine_2----------------------+
      int b=MathAbs((NormalizeDouble(Bid,Digits)-NormalizeDouble
           (ObjectGetValueByShift("Trendline "+2,0),Digits))*MathPow(10,Digits)/divider);
      if (___Show_$ == true){ string b$=" p = "+DoubleToStr(b*Pip_Lot,1)+" $       |  "+
                                  DoubleToStr(NormalizeDouble(b*Pip_Lot,1)*100/Deposit,1)+" % Acc ";}
      //+--
   if( _______________TrendLine_2==true) {
    ObjectCreate("TrendLine 2", OBJ_TREND, 0, Time[12], Bid-35*Point, Time[0]+3600, Bid-35*Point);
    ObjectSet("TrendLine 2", OBJPROP_COLOR, Line2);     
      if    (ObjectFind("2")==-1){ ObjectCreate("2",OBJ_TEXT, 0, 0, 0); 
   }  ObjectSetText("2",b+b$,9,"Arial",Line2);        
      ObjectSet("2",OBJPROP_PRICE1,NormalizeDouble(ObjectGetValueByShift("Trendline "+2,0),Digits)); 
             ObjectSet("2",OBJPROP_TIME1,objtime) ; 
  //----  
      double val2=ObjectGetValueByShift("Trendline 2", 0);
      if (Bid-Alert_pips*Point <= val2 && Bid+Alert_pips*Point >= val2)
     {   if (Sound_Alert) PlaySound (AlertSound);
         if (PopupON) Alert (Symbol()," price within ",Alert_pips," pips of ","Trendline 2");
         if (EmailON) SendMail(Symbol()+" ",Alert_pips+" pips from "+"Trendline 2"); } 
    }     else {ObjectDelete("TrendLine 2");}
    
 //+---------------------------+
   return(0);
  }