// LevelAlerter.mq4 — alerts when Bid crosses any horizontal line #property indicator_chart_window input bool UseSound = true; input bool UsePush = false; input int CooldownSeconds = 60; double prevBid = 0; datetime lastFire = 0; int OnInit() { prevBid = Bid; return(INIT_SUCCEEDED); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if(prevBid == 0) { prevBid = Bid; return(rates_total); } for(int i = ObjectsTotal() - 1; i >= 0; i--) { string name = ObjectName(i); if(ObjectType(name) != OBJ_HLINE) continue; double level = ObjectGet(name, OBJPROP_PRICE1); // crossed in either direction between the previous tick and this one bool crossed = (prevBid < level && Bid >= level) || (prevBid > level && Bid <= level); if(crossed && TimeCurrent() - lastFire >= CooldownSeconds) { string msg = StringFormat("%s %s crossed %s (%s)", Symbol(), DoubleToString(Bid, Digits), DoubleToString(level, Digits), name); if(UseSound) Alert(msg); // Alert() also writes to the Alerts tab if(UsePush) SendNotification(msg); // needs MetaQuotes ID in Options lastFire = TimeCurrent(); } } prevBid = Bid; return(rates_total); }