//+------------------------------------------------------------------+ //| H1H1_IB_Ind_V2.mq4 | //| Copyright © 2008-9, Robert Bayles | //| | //|******************************************************************| //| This indicator has been designed to meet the requirements of the | //| inside bar thread at: | //| http://www.forexfactory.com/showthread.php?t=133929 | //| | //| For the email alert function to operate, it must be configured | //| in the MetaTrader client terminal. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008-9, Robert Bayles" #property link "b.bayles@hotmail.com" #property indicator_chart_window extern string Note1 = "<-- Number of bars to test? -->"; extern int intNumberOfBars = 10; extern string Note2 = "<-- Indicator Line Length? -->"; extern int intLineLength = 5; extern string Note3 = "<-- Offset for Lines (Pips)? -->"; extern int intLineOffset = 3; extern string Note4 = "<- Include spread in buy indicator? ->"; extern bool bolBuySpread = false; extern string Note5 = "<-- Line Width (1 to 5)? -->"; extern int intLineWidth = 1; extern string Note6 = "<-- Line Colors? -->"; extern color colBuyLine = SteelBlue; extern color colSellLine = MediumPurple; extern string Note7 = "<-- Pop Up Alerts (True/False)? -->"; extern bool bolAlerts = true; extern string Note8 = "<-- Send Email Alert (True/False)? -->"; extern bool bolEMail = false; // Global Variables datetime dtCurrentTime; // Used with GetNewBar() function double dblPoints; // Variable for point value string strPeriod; // Variable for chart period in form of M15, H1, etc. //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { // Initialize time for GetNewBar() function dtCurrentTime = 0; // Set point value...needed if broker uses 3 or 5 decimals in price dblPoints = GetPoints(); // Verify that specified number of bars exists on chart if (intNumberOfBars > Bars) intNumberOfBars = Bars; // Get value for chart period and convert to string strPeriod = GetPeriod(); return(0); } // End function init() //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { DeleteObjects(); return(0); } // End function deinit() //+------------------------------------------------------------------+ //| Custom indicator start() function | //+------------------------------------------------------------------+ int start() { if (GetNewBar() == true) { DeleteObjects(); DrawObjects(); if (bolAlerts == true || bolEMail == true) ShowAlert(); } // End if return(0); } // End Function start() //+------------------------------------------------------------------+ //| Function DeleteObjects() //+------------------------------------------------------------------+ void DeleteObjects() { // Loop through bars for (int i=1; i <= intNumberOfBars; i++) { // If indicator is found... if (ObjectFind("IBBUY" + i) != -1) { ObjectDelete("IBBUY" + i); // Delete buy indicator ObjectDelete("IBSELL" + i); // Delete sell indicator } // End if } // Next i } // End Function DeleteObjects() //+------------------------------------------------------------------+ //| Function DrawObjects() Create indicator lines //+------------------------------------------------------------------+ void DrawObjects() { int intSpread; int intLength; double dblHigh; double dblLow; // Compute spread for buy indicator if (bolBuySpread == true) { intSpread = MarketInfo(Symbol(),MODE_SPREAD); // Correct spread for brokers that use 3 or 5 decimals in price if (Digits == 3 || Digits == 5) intSpread /= 10; // End nested if } else intSpread = 0; // End if/else // Loop through bars for ( int i = 1; i < intNumberOfBars; i++) { // Check to see if inside bar exists if(iHigh(NULL, 0, i) < iHigh(NULL, 0, i+1) && iLow(NULL, 0,i) > iLow(NULL, 0, i+1)) { // Correct indicator line length if number of bars showing are less than specified length intLength = intLineLength; if ( i < intLineLength) intLength = i+1; // Draw buy indicator dblHigh = iHigh(NULL,0,i+1) + ((intLineOffset + intSpread)* dblPoints); ObjectCreate("IBBUY" + i, OBJ_TREND, 0, Time[i+1], dblHigh, Time[(i+1) - intLength], dblHigh); ObjectSet("IBBUY" + i, OBJPROP_RAY, false); ObjectSet("IBBUY" + i, OBJPROP_WIDTH, intLineWidth); ObjectSet("IBBUY" + i, OBJPROP_COLOR, colBuyLine); // Draw sell indicator dblLow = iLow(NULL,0,i+1) - (intLineOffset * dblPoints); ObjectCreate("IBSELL" + i, OBJ_TREND, 0, Time[i+1], dblLow, Time[(i+1) - intLength], dblLow); ObjectSet("IBSELL" + i, OBJPROP_RAY, false); ObjectSet("IBSELL" + i, OBJPROP_WIDTH, intLineWidth); ObjectSet("IBSELL" + i, OBJPROP_COLOR, colSellLine); } // End if } // Next loop through bars } // End function DrawObjects() //+------------------------------------------------------------------+r //| Function GetNewBar() //+------------------------------------------------------------------+ bool GetNewBar() { // Check for a new bar if (dtCurrentTime != Time[0]) { dtCurrentTime = Time[0]; return(true); } else return(false); } // End Function GetNewBar() //-------------------------------------------------------------------+ // Function GetPoints() Correct point value if broker uses 3 or 5 // digits in price //-------------------------------------------------------------------+ double GetPoints() { if (Digits == 2 || Digits == 3) dblPoints = 0.01; else dblPoints = 0.0001; return(dblPoints); } // End Function GetPoints() //+------------------------------------------------------------------+ //| Function GetPeriod() Convert period in minutes to string //+------------------------------------------------------------------+ string GetPeriod() { switch(Period()) { case 1: strPeriod = "M1"; break; case 5: strPeriod = "M5"; break; case 15: strPeriod = "M15"; break; case 30: strPeriod = "M30"; break; case 60: strPeriod = "H1"; break; case 240: strPeriod = "H4"; break; case 1440: strPeriod = "D1"; break; case 10080: strPeriod = "W1"; break; case 43200: strPeriod = "MN1"; break; default: strPeriod = "Timeframe Error"; Alert("Chart Timeframe Not Supported!"); } // End switch return(strPeriod); } // End function GetPeriod() //+------------------------------------------------------------------+ //| Function ShowAlert() //+------------------------------------------------------------------+ void ShowAlert() { // If bolAlerts is true, show alert message if(iHigh(NULL, 0, 1) < iHigh(NULL, 0, 2) && iLow(NULL, 0, 1) > iLow(NULL, 0, 2)) { if (bolAlerts == true) Alert("Inside bar on " + Symbol() + " " + strPeriod); if (bolEMail == true) SendMail("From IB indicator", "Inside bar on " + Symbol() + " " + strPeriod); } // End if } // End function ShowAlert() //+------------------------------------------------------------------+ //| End of program //+------------------------------------------------------------------+