//+------------------------------------------------------------------+ //| GapCheck.mq4 | //| TradeAndSoftware | //| http://tasfx.net | //+------------------------------------------------------------------+ // //Update history //2015/09/14 MT4 Build600 was supported // Parameters all replacement #property copyright "TradeAndSoftware " #property link "http://tasfx.net" #property indicator_chart_window input int GapLabelCorner = 0; input int GapLabelX = 1; input int GapLabelY = 18; input color GapLabelColpr = clrWhite; input color GapLineColor = clrWhite; input int GapLineWidth = 2; input color HighLineColor = clrIndianRed; input color LowLineColor = clrRoyalBlue; input bool UseMTFMacdSignal = true; input int MacdCorner = 3; input int MacdTitleX = 1; input int MacdTitleY = 32; input color MacdTitleColor = clrWhite; input int MacdSignalX = 1; input int MacdSignalY = 1; input int MacdSignalWidth = 28; int digit = 0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //OpenClose ObjectCreate("OpenLine", OBJ_HLINE, 0, 0, 0); ObjectCreate("CloseLine", OBJ_HLINE, 0, 0, 0); ObjectCreate("GapLabel", OBJ_LABEL, 0, 0, 0); //D1 ObjectCreate("HighLineD1", OBJ_HLINE, 0, 0, 0); ObjectCreate("LowLineD1", OBJ_HLINE, 0, 0, 0); //H4 ObjectCreate("HighLineH4", OBJ_HLINE, 0, 0, 0); ObjectCreate("LowLineH4", OBJ_HLINE, 0, 0, 0); //H1 ObjectCreate("HighLineH1", OBJ_HLINE, 0, 0, 0); ObjectCreate("LowLineH1", OBJ_HLINE, 0, 0, 0); //M30 ObjectCreate("HighLineM30", OBJ_HLINE, 0, 0, 0); ObjectCreate("LowLineM30", OBJ_HLINE, 0, 0, 0); //M15 ObjectCreate("HighLineM15", OBJ_HLINE, 0, 0, 0); ObjectCreate("LowLineM15", OBJ_HLINE, 0, 0, 0); //M5 ObjectCreate("HighLineM5", OBJ_HLINE, 0, 0, 0); ObjectCreate("LowLineM5", OBJ_HLINE, 0, 0, 0); if(UseMTFMacdSignal) { //MTF MACD ObjectCreate("MTF_MACD_Title", OBJ_LABEL, 0, 0, 0); ObjectSet("MTF_MACD_Title", OBJPROP_CORNER, MacdCorner); ObjectSet("MTF_MACD_Title", OBJPROP_XDISTANCE, MacdTitleX); ObjectSet("MTF_MACD_Title", OBJPROP_YDISTANCE, MacdTitleY); ObjectSetText("MTF_MACD_Title", "MACD M5 M15 M30 H1 H4 D1", 8, "Arial", clrWhite); int signalX = MacdSignalX; ObjectCreate("MTF_MACD_D1", OBJ_LABEL, 0, 0, 0); ObjectSet("MTF_MACD_D1", OBJPROP_CORNER, MacdCorner); ObjectSet("MTF_MACD_D1", OBJPROP_XDISTANCE, signalX); ObjectSet("MTF_MACD_D1", OBJPROP_YDISTANCE, MacdSignalY); signalX += MacdSignalWidth; ObjectCreate("MTF_MACD_H4", OBJ_LABEL, 0, 0, 0); ObjectSet("MTF_MACD_H4", OBJPROP_CORNER, MacdCorner); ObjectSet("MTF_MACD_H4", OBJPROP_XDISTANCE, signalX); ObjectSet("MTF_MACD_H4", OBJPROP_YDISTANCE, MacdSignalY); signalX += MacdSignalWidth; ObjectCreate("MTF_MACD_H1", OBJ_LABEL, 0, 0, 0); ObjectSet("MTF_MACD_H1", OBJPROP_CORNER, MacdCorner); ObjectSet("MTF_MACD_H1", OBJPROP_XDISTANCE, signalX); ObjectSet("MTF_MACD_H1", OBJPROP_YDISTANCE, MacdSignalY); signalX += MacdSignalWidth; ObjectCreate("MTF_MACD_M30", OBJ_LABEL, 0, 0, 0); ObjectSet("MTF_MACD_M30", OBJPROP_CORNER, MacdCorner); ObjectSet("MTF_MACD_M30", OBJPROP_XDISTANCE, signalX); ObjectSet("MTF_MACD_M30", OBJPROP_YDISTANCE, MacdSignalY); signalX += MacdSignalWidth; ObjectCreate("MTF_MACD_M15", OBJ_LABEL, 0, 0, 0); ObjectSet("MTF_MACD_M15", OBJPROP_CORNER, MacdCorner); ObjectSet("MTF_MACD_M15", OBJPROP_XDISTANCE, signalX); ObjectSet("MTF_MACD_M15", OBJPROP_YDISTANCE, MacdSignalY); signalX += MacdSignalWidth; ObjectCreate("MTF_MACD_M5", OBJ_LABEL, 0, 0, 0); ObjectSet("MTF_MACD_M5", OBJPROP_CORNER, MacdCorner); ObjectSet("MTF_MACD_M5", OBJPROP_XDISTANCE, signalX); ObjectSet("MTF_MACD_M5", OBJPROP_YDISTANCE, MacdSignalY); } digit = Digits(); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("OpenLine"); ObjectDelete("CloseLine"); ObjectDelete("GapLabel"); ObjectDelete("HighLineD1"); ObjectDelete("LowLineD1"); ObjectDelete("HighLineH4"); ObjectDelete("LowLineH4"); ObjectDelete("HighLineH1"); ObjectDelete("LowLineH1"); ObjectDelete("HighLineM30"); ObjectDelete("LowLineM30"); ObjectDelete("HighLineM15"); ObjectDelete("LowLineM15"); ObjectDelete("HighLineM5"); ObjectDelete("LowLineM5"); if(UseMTFMacdSignal) { ObjectDelete("MTF_MACD_Title"); ObjectDelete("MTF_MACD_D1"); ObjectDelete("MTF_MACD_H4"); ObjectDelete("MTF_MACD_H1"); ObjectDelete("MTF_MACD_M30"); ObjectDelete("MTF_MACD_M15"); ObjectDelete("MTF_MACD_M5"); } //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); double gap; //---- for(int i=counted_bars-1; i>=0; i--) { int dayOfWeekNow=TimeDayOfWeek(Time[i]); int dayOfWeekBef=TimeDayOfWeek(Time[i+1]); if(dayOfWeekNow == 1 && dayOfWeekBef != 1) { ObjectSet("OpenLine", OBJPROP_PRICE1, Open[i]); ObjectSet("OpenLine", OBJPROP_COLOR, GapLineColor); ObjectSet("OpenLine", OBJPROP_WIDTH, GapLineWidth); if(Open[i] > High[i+1]) { ObjectSet("CloseLine", OBJPROP_PRICE1, High[i+1]); if(digit == 3) { gap = (Open[i] - High[i+1]) * 100; } else if(digit == 5) { gap = (Open[i] - High[i+1]) * 10000; } } else if(Low[i+1] > Open[i]) { ObjectSet("CloseLine", OBJPROP_PRICE1, Low[i+1]); if(digit == 3) { gap = (Low[i+1] - Open[i]) * 100; } else if(digit == 5) { gap = (Low[i+1] - Open[i]) * 10000; } } ObjectSet("CloseLine", OBJPROP_COLOR, GapLineColor); ObjectSet("CloseLine", OBJPROP_WIDTH, GapLineWidth); //GAP LABEL ObjectSet("GapLabel", OBJPROP_CORNER, GapLabelCorner); ObjectSet("GapLabel", OBJPROP_XDISTANCE,GapLabelX); ObjectSet("GapLabel", OBJPROP_YDISTANCE,GapLabelY); ObjectSet("GapLabel", OBJPROP_COLOR, GapLabelColpr); ObjectSetText("GapLabel", "GAP:" + DoubleToStr(MathAbs(gap), 1)); } } ObjectSet("HighLineD1", OBJPROP_PRICE1, iHigh(NULL, PERIOD_D1, 1)); ObjectSet("HighLineD1", OBJPROP_COLOR, HighLineColor); ObjectSet("HighLineD1", OBJPROP_STYLE, STYLE_DASH); ObjectSet("LowLineD1", OBJPROP_PRICE1, iLow(NULL, PERIOD_D1, 1)); ObjectSet("LowLineD1", OBJPROP_COLOR, LowLineColor); ObjectSet("LowLineD1", OBJPROP_STYLE, STYLE_DASH); if(Period() <= 240) { ObjectSet("HighLineH4", OBJPROP_PRICE1, iHigh(NULL, PERIOD_H4, 1)); ObjectSet("HighLineH4", OBJPROP_COLOR, HighLineColor); ObjectSet("HighLineH4", OBJPROP_STYLE, STYLE_DOT); ObjectSet("LowLineH4", OBJPROP_PRICE1, iLow(NULL, PERIOD_H4, 1)); ObjectSet("LowLineH4", OBJPROP_COLOR, LowLineColor); ObjectSet("LowLineH4", OBJPROP_STYLE, STYLE_DOT); } else { ObjectDelete("HighLineH4"); ObjectDelete("LowLineH4"); } if(Period() <= 60) { ObjectSet("HighLineH1", OBJPROP_PRICE1, iHigh(NULL, PERIOD_H1, 1)); ObjectSet("HighLineH1", OBJPROP_COLOR, HighLineColor); ObjectSet("HighLineH1", OBJPROP_STYLE, STYLE_DOT); ObjectSet("LowLineH1", OBJPROP_PRICE1, iLow(NULL, PERIOD_H1, 1)); ObjectSet("LowLineH1", OBJPROP_COLOR, LowLineColor); ObjectSet("LowLineH1", OBJPROP_STYLE, STYLE_DOT); } else { ObjectDelete("HighLineH1"); ObjectDelete("LowLineH1"); } if(Period() <= 30) { ObjectSet("HighLineM30", OBJPROP_PRICE1, iHigh(NULL, PERIOD_M30, 1)); ObjectSet("HighLineM30", OBJPROP_COLOR, HighLineColor); ObjectSet("HighLineM30", OBJPROP_STYLE, STYLE_DOT); ObjectSet("LowLineM30", OBJPROP_PRICE1, iLow(NULL, PERIOD_M30, 1)); ObjectSet("LowLineM30", OBJPROP_COLOR, LowLineColor); ObjectSet("LowLineM30", OBJPROP_STYLE, STYLE_DOT); } else { ObjectDelete("HighLineM30"); ObjectDelete("LowLineM30"); } if(Period() <= 15) { ObjectSet("HighLineM15", OBJPROP_PRICE1, iHigh(NULL, PERIOD_M15, 1)); ObjectSet("HighLineM15", OBJPROP_COLOR, HighLineColor); ObjectSet("HighLineM15", OBJPROP_STYLE, STYLE_DOT); ObjectSet("LowLineM15", OBJPROP_PRICE1, iLow(NULL, PERIOD_M15, 1)); ObjectSet("LowLineM15", OBJPROP_COLOR, LowLineColor); ObjectSet("LowLineM15", OBJPROP_STYLE, STYLE_DOT); } else { ObjectDelete("HighLineM15"); ObjectDelete("LowLineM15"); } if(Period() <= 5) { ObjectSet("HighLineM5", OBJPROP_PRICE1, iHigh(NULL, PERIOD_M5, 1)); ObjectSet("HighLineM5", OBJPROP_COLOR, HighLineColor); ObjectSet("HighLineM5", OBJPROP_STYLE, STYLE_DOT); ObjectSet("LowLineM5", OBJPROP_PRICE1, iLow(NULL, PERIOD_M5, 1)); ObjectSet("LowLineM5", OBJPROP_COLOR, LowLineColor); ObjectSet("LowLineM5", OBJPROP_STYLE, STYLE_DOT); } else { ObjectDelete("HighLineM5"); ObjectDelete("LowLineM5"); } //MTF MACD if(UseMTFMacdSignal) { double macd_d1 = iMACD(NULL, PERIOD_D1, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0); double signal_d1 = iMACD(NULL, PERIOD_D1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0); if(macd_d1 > 0) { if(macd_d1 > signal_d1) { ObjectSetText("MTF_MACD_D1", CharToStr(71), 16, "Wingdings", Red); } else { ObjectSetText("MTF_MACD_D1", CharToStr(71), 16, "Wingdings", Coral); } } else { if(signal_d1 > macd_d1) { ObjectSetText("MTF_MACD_D1", CharToStr(72), 16, "Wingdings", RoyalBlue); } else { ObjectSetText("MTF_MACD_D1", CharToStr(72), 16, "Wingdings", DeepSkyBlue); } } double macd_h4 = iMACD(NULL, PERIOD_H4, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0); double signal_h4 = iMACD(NULL, PERIOD_H4, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0); if(macd_h4 > 0) { if(macd_h4 > signal_h4) { ObjectSetText("MTF_MACD_H4", CharToStr(71), 16, "Wingdings", Red); } else { ObjectSetText("MTF_MACD_H4", CharToStr(71), 16, "Wingdings", Coral); } } else { if(signal_h4 > macd_h4) { ObjectSetText("MTF_MACD_H4", CharToStr(72), 16, "Wingdings", RoyalBlue); } else { ObjectSetText("MTF_MACD_H4", CharToStr(72), 16, "Wingdings", DeepSkyBlue); } } double macd_h1 = iMACD(NULL, PERIOD_H1, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0); double signal_h1 = iMACD(NULL, PERIOD_H1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0); if(macd_h1 > 0) { if(macd_h1 > signal_h1) { ObjectSetText("MTF_MACD_H1", CharToStr(71), 16, "Wingdings", Red); } else { ObjectSetText("MTF_MACD_H1", CharToStr(71), 16, "Wingdings", Coral); } } else { if(signal_h1 > macd_h1) { ObjectSetText("MTF_MACD_H1", CharToStr(72), 16, "Wingdings", RoyalBlue); } else { ObjectSetText("MTF_MACD_H1", CharToStr(72), 16, "Wingdings", DeepSkyBlue); } } double macd_m30 = iMACD(NULL, PERIOD_M30, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0); double signal_m30 = iMACD(NULL, PERIOD_M30, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0); if(macd_m30 > 0) { if(macd_m30 > signal_m30) { ObjectSetText("MTF_MACD_M30", CharToStr(71), 16, "Wingdings", Red); } else { ObjectSetText("MTF_MACD_M30", CharToStr(71), 16, "Wingdings", Coral); } } else { if(signal_m30 > macd_m30) { ObjectSetText("MTF_MACD_M30", CharToStr(72), 16, "Wingdings", RoyalBlue); } else { ObjectSetText("MTF_MACD_M30", CharToStr(72), 16, "Wingdings", DeepSkyBlue); } } double macd_m15 = iMACD(NULL, PERIOD_M15, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0); double signal_m15 = iMACD(NULL, PERIOD_M15, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0); if(macd_m15 > 0) { if(macd_m15 > signal_m15) { ObjectSetText("MTF_MACD_M15", CharToStr(71), 16, "Wingdings", Red); } else { ObjectSetText("MTF_MACD_M15", CharToStr(71), 16, "Wingdings", Coral); } } else { if(signal_m15 > macd_m15) { ObjectSetText("MTF_MACD_M15", CharToStr(72), 16, "Wingdings", RoyalBlue); } else { ObjectSetText("MTF_MACD_M15", CharToStr(72), 16, "Wingdings", DeepSkyBlue); } } double macd_m5 = iMACD(NULL, PERIOD_M5, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 0); double signal_m5 = iMACD(NULL, PERIOD_M5, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0); if(macd_m5 > 0) { if(macd_m5 > signal_m5) { ObjectSetText("MTF_MACD_M5", CharToStr(71), 16, "Wingdings", Red); } else { ObjectSetText("MTF_MACD_M5", CharToStr(71), 16, "Wingdings", Coral); } } else { if(signal_m5 > macd_m5) { ObjectSetText("MTF_MACD_M5", CharToStr(72), 16, "Wingdings", RoyalBlue); } else { ObjectSetText("MTF_MACD_M5", CharToStr(72), 16, "Wingdings", DeepSkyBlue); } } } //---- return(0); } //+------------------------------------------------------------------+