Author: Copyright � 2009, ������������� v.1.1
PriceAlert

This script is designed as a visual and audible monitoring tool for traders using the MetaTrader platform. Its primary purpose is to allow you to set a specific price "alert level" on your trading chart and receive an immediate notification—either through a pop-up window or a sound effect—the moment the market price touches or crosses that designated line.

Key Functionalities

Visual Price Monitoring The tool automatically places a horizontal reference line on your chart. This provides a clear visual boundary for your trades, such as a target profit level or a significant support/resistance zone. Along with this line, the script displays a dynamic text label that calculates and shows the real-time distance (in pips) between the current market price and your alert level.

Dynamic Distance Calculation As the market fluctuates, the script constantly performs "under-the-hood" math to determine how far the current price is from your set line. This allows you to see at a glance how close the market is getting to your desired trigger point without having to manually calculate the difference.

Automated Alert System The core logic of the script is its ability to "watch" the price for you:

  • Trigger Detection: The system constantly compares the live market bid price against your alert level. If the price moves from below the line to touch/cross it, or from above the line to touch/cross it, the alert is triggered.
  • User Notifications: Depending on your preferences, the script will notify you via a pop-up window containing the specific symbol name and the price at which the alert occurred, or it will play a custom sound file.
  • State Management: To prevent the system from constantly alerting you every second while the price stays on the line, the script intelligently switches to an "Inactive" state once a trigger has occurred. This ensures you are only notified of the initial breach.

User Experience Features

  • Customization: Users can choose the color and thickness of the alert line to make it stand out on different chart backgrounds.
  • Smart Scaling: The script automatically detects whether you are trading on a 3-digit or 5-digit broker, ensuring that the "Pip" calculations remain accurate regardless of your specific account type.
  • Visual Feedback: The text labels on the chart change dynamically to inform you whether the alert level is currently "Active" (ready to trigger) or "Inactive" (already triggered or disabled).
Miscellaneous
It issuies visual alerts to the screenIt plays sound alerts
13 Views
0 Downloads
0 Favorites
PriceAlert
//+------------------------------------------------------------------+
//|                                                   PriceAlert.mq4 |
//|                            Copyright © 2009, ÏàâåëÈâàíîâè÷ (api) |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, ÏàâåëÈâàíîâè÷ v.1.1"
#property link      ""

#property indicator_chart_window
//---- input parameters
extern color     LineColor=Red;
extern int       LineWidth=2;
extern bool      PopupWindow=true;
extern string    Sound="Alert.wav";
extern string    UniqueName="Price 1";

double LastLevel;
double LastPrice;
double TradePoint;

bool Active;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   LastLevel=0;
   LastPrice=0;
   Active=true;
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   int reason = UninitializeReason();
   if(UninitializeReason() == REASON_REMOVE) ObjectDelete(UniqueName);
   else ObjectSetText(UniqueName,"Price alert level - Inactive",0);
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if(Digits==3 || Digits==5) TradePoint = Point*10;
   else TradePoint = Point;
   string PipsTextName = StringConcatenate(UniqueName," ","Pips");
   if(ObjectFind(UniqueName)==-1)
   {
      double cp = LastLevel;
      if(cp==0) cp = Ask+20*TradePoint;
      ObjectCreate(UniqueName,OBJ_HLINE,0,0,cp);
      ObjectSetText(UniqueName,"Price alert level",0);
      ObjectSet(UniqueName,OBJPROP_COLOR,LineColor);
      ObjectSet(UniqueName,OBJPROP_WIDTH,LineWidth);
   }
   if(ObjectFind(PipsTextName)==-1)
   {
      cp = LastLevel;
      if(cp==0) cp = Ask+20*TradePoint;
      ObjectCreate(PipsTextName,OBJ_TEXT,0,Time[0],cp);
   }
   double newlevel = ObjectGet(UniqueName,OBJPROP_PRICE1);
   ObjectSet(PipsTextName,OBJPROP_TIME1,Time[0]);
   if(Active)
   {
      double Pips = MathAbs(NormalizeDouble(newlevel,Digits)-Bid)/TradePoint;
      if(Digits==3 || Digits==5)
         ObjectSetText(PipsTextName,DoubleToStr(Pips,1),12,"Arial",LineColor);
      else
         ObjectSetText(PipsTextName,DoubleToStr(Pips,0),12,"Arial",LineColor);
   }
   ObjectSet(PipsTextName,OBJPROP_PRICE1,newlevel);
   if(LastLevel!=newlevel)
   {
      LastLevel = newlevel;
      LastPrice=0;
      ObjectSetText(UniqueName,"Price alert level - Active",0);
      Active = true;
   }
   if(Active && LastPrice!=0 && ((LastPrice<LastLevel && Bid>=LastLevel) || (LastPrice>LastLevel && Bid<=LastLevel)))
   {
      if(PopupWindow)
      {
         Alert(Symbol()+" Price alert level triggered at " + DoubleToStr(Bid,Digits) + ". Please activate alert level.");
      }else
         PlaySound(Sound);
      Active = false;
      ObjectSetText(PipsTextName,"",12,"Arial",LineColor);
      ObjectSetText(UniqueName,"Price alert level - Inactive",0);
   }
   LastPrice = Bid;
   return(0);
}
//+------------------------------------------------------------------+

Comments