BalanceOfPower_Histogram_Alert - MetaTrader 5 script




This Balance of Power (BOP) indicator serves as a color histogram of the strength and direction of the current trend, with the ability to alert, send emails, and push notifications to mobile devices. The histogram is colored based on the input parameter values for overbought and oversold levels and the direction of movement of the histogram.
In order to implement alerts, email messages and push notifications, the following changes were made to the indicator code:
//---- Input variables for alerts Input unit number = 1 ; //The number of bars of the signal Input boolean sound on = true ; //enable alert Input unit alarm number = 2 ; //Alarm number input boolean email-on = false ; //enable mailing signal input boolean pressed = false ; //enable signaling to mobile devices
//+------------------------------------------------------------------+ //|Buy signal function | //+------------------------------------------------------------------+ Blank buy signal( string signal sir name, // indicator name text for emails and push messages double & color array[], // color index buffer integer color index, // color index in color index buffer to generate signal constant integer rate_total, // current number of bars constant integer pre_calculation, // number of bars of the previous price move constant double & close [], // closing price constant integer & spread[]) // spread { //--- Static unit counter = 0 ; if (Rates_total!=Prev_calculated) counter = 0 ; boolean buysignal = false ; booleanSeriesTest = array getSeries (ColorArray); integer index, index 1; if (series test) { Index = integer (number of items); index1=index+ 1 ; } other { Index=Rates_total- integer (number of items) -1 ; index1=index- 1 ; } if (ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) BuySignal= true ; if (BuySignal && counter<=NumberofAlerts) { counter++; MqlDateTimeTM ; BuildTime ( timecurrent (),tm); string literal = string time ( timecurrent (), TIME_DATE ) + "" + string (tm.hour) + ":" + string (tm.minute); SeriesTest = arrayGetSeries ( close ); if (series test) index = integer (number of items); Other indexes=Rates_total- integer (number of items) -1 ; double question = close [index]; double bid = close [index]; SeriesTest = arrayGetSeries (spread); if (series test) index = integer (number of items); Other indexes=Rates_total- integer (number of items) -1 ; bid += spread[index]; Thin string question = double to string ( question , _number ); stringbid = double to string ( bid , _number ); String sPeriod=GetStringTimeframe( ChartPeriod ()); if (sound on) alert ( "buy signal\n ask=" , ask , "\n bid=" , bid , "\n current time=" , text, "\n symbol=" , symbol (), "period=" ,s period); If (email) send mail (signal sir name + ":buy signal alert" , "buy signal at inquiry=" +ask+ ", bid=" +bid+ ", dayperiod = " + text + " symbol = " + symbol () + " period = " + s period); if (push) send notification (signal sir name + ": Buy signal at Ask = " , bid =" + bid + ", date =" + text + " symbol = " + symbol () + " period = " + s period); } //--- } //+--------------------------------------------------------------------------------+ //|Sell signal function | //+------------------------------------------------------------------+ Blank Sell Signal ( Thin String Signal Mr. Name, // Indicator Name Text for Emails and Push Messages Double & Color Array[], // Color Index Buffer Integer Color Index, // Color Index in Color Index Buffer Generate Signal Constant Integer Rate_Total, // Current Bar Constant Integer Before_Calculation, // Previous Price Move Bar Constant Double & Close [], // Closing Price Constant Integer & Spread[]) // propagation { //--- static units counter = 0 ; if (Rates_total!=Prev_calculated) counter = 0 ; boolean sell signal = false ; boolean series test = array getSeries (colorarray); integer index, index 1; if (series test) { index = integer (number of bars); index 1 = index + 1 ; } else { index = Rates_total - integer (number of bars) - 1 ; Index1 = Index - 1 ; } if (ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) SellSignal = True ; if (SellSignal && Counter <= NumberofAlerts) { Counter++; MqlDateTimeTM ; BuildTime ( TimeCurrent (), tm); String literal = String Time ( TimeCurrent (), TIME_DATE ) + "" + string (tm.hour)+ ":" + string (tm.minute); series test = array to get series ( closed ); if (series test) index = integer (number of items); other index = Rates_total - integer (number of items) - 1 ; double ask = close [index]; double bid = close [index]; SeriesTest = Array Get Series (Spread); if (SeriesTest) Index = Integer (Number of Bars); Else Index = Rates_total - Integer (Number of Bars) - 1 ; Bid + = Spread [Index]; String Ask = Double to String ( Q , _Number ); String Bid = Double to String ( Bid , _Number ); String sPeriod = GetStringTimeframe( ChartPeriod ()); If (Sound On) Alert ( "Sell Signal\n Ask=" , Ask , “\nBid=" , bid , "\n current time=" ,text, "\n symbol=" , symbol (), "period=" ,s period); if (email) send mail (signal sir name + ": sell signal alert" , "sell signal in ask=" +ask+ ",bid=" +bid+ ",date=" +text+ "symbol=" + symbol ()+ "period=" +s period); if (pushed) send notification (signal sir name + ": Sell signal on Ask=" + ask + ", bid =" + bid + ", date =" + text + " symbol =" + symbol () + " period = " +s period); } //--- } //+--------------------------------------------------------------------------------+ //| Get the time range as a string | //+--------------------------------------------------------------------------------+ String Get the time range as a string ( ENUM_TIMEFRAMES approximate time) { //---- return ( string substring ( enumeration to string (approximate time), 7 ,- 1 )); //---- }
//--- Buy signal ( “BalanceOfPower_Histogram_Alert” ,ColorIndBuffer, 0 ,rates_total,prev_calculated,close,spread); Sell signal ( “BalanceOfPower_Histogram_Alert” ,ColorIndBuffer, 7 ,rates_total,prev_calculated,close,spread); //---
Where ColorIndBuffer is the name of the color index buffer used to store candle colors in indexed form.
It is assumed that the only calls to the BuySignal() and SellSignal() functions will be used in the OnCalculate() block of the indicator code.
The indicator uses the class SmoothAlgorithms.mqh library (copy it to
The indicator was originally written in MQL5 and first published in the code base on February 7, 2013.

Figure 1. BalanceOfPower_Histogram_Alert indicator on the chart
Figure 2. The BalanceOfPower_Histogram_Alert indicator generates an alert.
Attachment download
📎 BalanceOfPower_Histogram_Alert.mq5 (29.17 KB)
📎 SmoothAlgorithms.mqh (130.2 KB)
Source: MQL5 #16403
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •