//+------------------------------------------------------------------+
//|                                          Price Line alert v2.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window

#include <hanover --- function header.mqh>

extern bool   ShowBuyLine             = true;
extern color  BuyLineColor            = Green; 
extern int    BuyLineStyle            = STYLE_DASH;
extern int    BuyAlert_Pip_Distance   = 0;

extern bool   ShowSellLine            = true;
extern color  SellLineColor           = Red; 
extern int    SellLineStyle           = STYLE_DASH;
extern int    SellAlert_Pip_Distance  = 0;

string     ccy, IndiName, BuyLineName, SellLineName;
int        dig, tf, tmf, vis, wno, RefreshEveryXMins;
double     spr, pnt, tickval, bidp, askp, minlot, lswap, sswap, BuyValue, SellValue, price;

//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+
  IndiName = "PLA-";
  IndicatorShortName(IndiName);

  ccy     = Symbol();
  tmf     = Period();
  bidp    = MarketInfo(ccy,MODE_BID);
  askp    = MarketInfo(ccy,MODE_ASK);
  pnt     = MarketInfo(ccy,MODE_POINT);
  dig     = MarketInfo(ccy,MODE_DIGITS);
  spr     = MarketInfo(ccy,MODE_SPREAD);
  tickval = MarketInfo(ccy,MODE_TICKVALUE);
  minlot  = MarketInfo(ccy,MODE_MINLOT);
  lswap   = MarketInfo(ccy,MODE_SWAPLONG);
  sswap   = MarketInfo(ccy,MODE_SWAPSHORT);
  if (dig == 3 || dig == 5) {
    pnt     *= 10;
    spr     /= 10;
    tickval *= 10;
  } 

  del_obj();
  BuyLineName  = IndiName + "buy";
  SellLineName = IndiName + "sell";
  BuyValue     = NormalizeDouble(askp+(askp-bidp),dig);
  SellValue    = NormalizeDouble(bidp-(askp-bidp),dig);
  if (ShowBuyLine)  {
    ObjectCreate(BuyLineName, OBJ_HLINE, 0, 0, BuyValue);
    ObjectSet(BuyLineName, OBJPROP_STYLE, BuyLineStyle);
    ObjectSet(BuyLineName, OBJPROP_COLOR, BuyLineColor);
  }  
  if (ShowSellLine)  {
    ObjectCreate(SellLineName, OBJ_HLINE, 0, 0, SellValue);
    ObjectSet(SellLineName, OBJPROP_STYLE, SellLineStyle);
    ObjectSet(SellLineName, OBJPROP_COLOR, SellLineColor);
  }  
  WindowRedraw();

  return(0);
}

//+------------------------------------------------------------------+
void del_obj()  {
//+------------------------------------------------------------------+
  int k=0;
  while (k<ObjectsTotal())   {
    string objname = ObjectName(k);
    if (StringSubstr(objname,0,StringLen(IndiName)) == IndiName)  
      ObjectDelete(objname);
    else
      k++;
  }    
  return(0);
}

//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  del_obj();
  return(0);
}

//+------------------------------------------------------------------+
int start()  {
//+------------------------------------------------------------------+
  if (Bid-BuyAlert_Pip_Distance*pnt <= BuyValue && Bid+BuyAlert_Pip_Distance*pnt >= BuyValue && ObjectFind(BuyLineName) >= 0)  {
    price = ObjectGet(BuyLineName, OBJPROP_PRICE1);
    if (price > 0)  {   
      Alert(Symbol() + "," + TFToStr(Period()) + ": Buy line reached");
      ObjectSet(BuyLineName,OBJPROP_PRICE1,0.0);
      WindowRedraw();
  } } 

  if (Bid-SellAlert_Pip_Distance*pnt <= SellValue && Bid+SellAlert_Pip_Distance*pnt >= SellValue && ObjectFind(SellLineName) >= 0)  {
    price = ObjectGet(SellLineName, OBJPROP_PRICE1);
    if (price > 0)  {   
      Alert(Symbol() + "," + TFToStr(Period()) + ": Sell line reached");
      ObjectSet(SellLineName,OBJPROP_PRICE1,0.0);
      WindowRedraw();
  } }  
  return(0);
}

//+------------------------------------------------------------------+
#include <hanover --- extensible functions.mqh>