//+------------------------------------------------------------------+ //| ichimokusuppresmtf_ad.mq4 | //+------------------------------------------------------------------+ #property copyright "Scriptong" #property link "http://advancetools.net" #property description "English: Support and resistance levels based on Ichimoku cloud. Multitimeframe version.\nRussian: Уровни поддержки и сопротивления на основе облака Ichimoku. Мультипериодная версия." #property version "2.00" #property strict #property indicator_chart_window #property indicator_buffers 0 #define PREFIX "ICSUREMTF_" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_YESNO { NO, // No / Нет YES // Yes / Да }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_CUSTOM_TF { TF_NOT_USED = 0, // Not used / Не использовать TF_M1 = PERIOD_M1, // 1 Minute / 1 Минута TF_M5 = PERIOD_M5, // 5 Minutes / 5 Минут TF_M15 = PERIOD_M15, // 15 Minutes / 15 Минут TF_M30 = PERIOD_M30, // 30 Minutes / 30 Минут TF_H1 = PERIOD_H1, // 1 Hour / 1 Час TF_H4 = PERIOD_H4, // 4 Hours / 4 Часа TF_D1 = PERIOD_D1, // 1 Day / 1 День TF_W1 = PERIOD_W1, // 1 Week / 1 Неделя TF_MN1 = PERIOD_MN1, // 1 Month / 1 Месяц }; input uint i_tenkanSenPeriod = 9; // Tenkan-sen period / Период расчета Tenkan-sen input uint i_kijunSenPeriod = 26; // Kijun-sen period / Период расчета Kijun-sen input uint i_senkouSpanPeriod = 52; // Senkou Span B period / Период расчета Senkou Span B input uint i_fractalRank = 13; // Fractal rank / Ранг фрактала input string i_string0End = ""; //   input ENUM_CUSTOM_TF i_tf1 = TF_H4; // Time frame 1 / Таймфрейм 1 input color i_support1Color = clrDodgerBlue; // Color of support lines / Цвет линий поддержки input ENUM_LINE_STYLE i_support1Style = STYLE_DOT; // Style of support lines / Тип линий поддержки input uint i_support1Width = 0; // Thickness of support lines / Толщина линий поддержки input color i_resistance1Color = clrMaroon; // Color of resistance lines / Цвет линий сопротивления input ENUM_LINE_STYLE i_resistance1Style = STYLE_DOT; // Style of resistance lines / Тип линий сопротивления input uint i_resistance1Width = 0; // Thickness of resistance lines / Толщина линий сопротивления input string i_string1End = ""; //   input ENUM_CUSTOM_TF i_tf2 = TF_D1; // Time frame 2 / Таймфрейм 2 input color i_support2Color = clrTurquoise; // Color of support lines / Цвет линий поддержки input ENUM_LINE_STYLE i_support2Style = STYLE_SOLID; // Style of support lines / Тип линий поддержки input uint i_support2Width = 1; // Thickness of support lines / Толщина линий поддержки input color i_resistance2Color = clrBrown; // Color of resistance lines / Цвет линий сопротивления input ENUM_LINE_STYLE i_resistance2Style = STYLE_SOLID; // Style of resistance lines / Тип линий сопротивления input uint i_resistance2Width = 1; // Thickness of resistance lines / Толщина линий сопротивления input string i_string2End = ""; //   input ENUM_CUSTOM_TF i_tf3 = TF_W1; // Time frame 3 / Таймфрейм 3 input color i_support3Color = clrBlue; // Color of support lines / Цвет линий поддержки input ENUM_LINE_STYLE i_support3Style = STYLE_SOLID; // Style of support lines / Тип линий поддержки input uint i_support3Width = 2; // Thickness of support lines / Толщина линий поддержки input color i_resistance3Color = clrRed; // Color of resistance lines / Цвет линий сопротивления input ENUM_LINE_STYLE i_resistance3Style = STYLE_SOLID; // Style of resistance lines / Тип линий сопротивления input uint i_resistance3Width = 2; // Thickness of resistance lines / Толщина линий сопротивления input string i_string3End = ""; //   input int i_indBarsCount=10000; // Number of bars to display / Кол-во баров отображения //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_MESSAGE_CODE { MESSAGE_CODE_INVALID_FRACTAL_RANK1, MESSAGE_CODE_INVALID_FRACTAL_RANK2, MESSAGE_CODE_MA_SLOW_LESS_THAN_ZERO, MESSAGE_CODE_TERMINAL_FATAL_ERROR1, MESSAGE_CODE_NOT_ENOUGHT_MEMORY }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ struct TFParam { ENUM_TIMEFRAMES tf; color supportColor; ENUM_LINE_STYLE supportStyle; uint supportWidth; color resistanceColor; ENUM_LINE_STYLE resistanceStyle; uint resistanceWidth; }; // Global variables bool g_activate; int g_tfsCnt, g_centerBar, g_sidesBars, g_maxPeriod; TFParam g_tfParam[]; //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Custom indicator initialization function | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ int OnInit() { g_activate=false; if(!TuningParameters()) return INIT_FAILED; g_tfsCnt=0; if(!IsTFCopy(i_tf1,i_support1Color,i_support1Style,i_support1Width,i_resistance1Color,i_resistance1Style,i_resistance1Width) || !IsTFCopy(i_tf2,i_support2Color,i_support2Style,i_support2Width,i_resistance2Color,i_resistance2Style,i_resistance2Width) || !IsTFCopy(i_tf3,i_support3Color,i_support3Style,i_support3Width,i_resistance3Color,i_resistance3Style,i_resistance3Width)) return INIT_FAILED; g_activate=true; return INIT_SUCCEEDED; } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Checking the correctness of values of tuning parameters | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ bool TuningParameters() { string name=WindowExpertName(); if(i_fractalRank<3) { Alert(name,GetStringByMessageCode(MESSAGE_CODE_INVALID_FRACTAL_RANK1)); return false; } if(i_fractalRank%2==0) { Alert(name,GetStringByMessageCode(MESSAGE_CODE_INVALID_FRACTAL_RANK2)); return false; } g_centerBar = (int)i_fractalRank / 2 + 1; g_sidesBars = (int)i_fractalRank / 2; g_maxPeriod=(int)MathMax(i_tenkanSenPeriod,MathMax(i_kijunSenPeriod,i_senkouSpanPeriod)); return true; } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Copying the timeframe parameters to array | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ bool IsTFCopy(ENUM_CUSTOM_TF tf,color supportColor,ENUM_LINE_STYLE supportStyle,uint supportWidth,color resistanceColor,ENUM_LINE_STYLE resistanceStyle,uint resistanceWidth) { if(tf==TF_NOT_USED || (int)tf0 && i_indBarsCount=totalBars) return false; double curHigh=iHigh(NULL,tf,barIndex); // On right of bar for(int i=barIndex-g_sidesBars; i=curHigh) return false; // On left of bar int leftBar=barIndex+g_sidesBars; for(int i=barIndex+1; i<=leftBar; i++) { double high=iHigh(NULL,tf,i); if(high>curHigh) return false; if(high==curHigh) { leftBar++; if(leftBar>=totalBars) return false; } } return true; } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Finding the down fractal | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ bool IsDownFractal(ENUM_TIMEFRAMES tf,int barIndex) { int totalBars=iBars(NULL,tf); if(barIndex-g_sidesBars<=0 || barIndex+g_sidesBars>=totalBars) return false; double curLow=iLow(NULL,tf,barIndex); // On right of bar for(int i=barIndex-g_sidesBars; i=totalBars) return false; } } return true; } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Add bars value to time and cast the result to time | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ datetime AddBarsToTime(ENUM_TIMEFRAMES tf,datetime startTime,int addBars) { int startBar = iBarShift(NULL, tf, startTime); int barsSumm = startBar - addBars; int barsCount= iBars(NULL,tf); datetime curTimeBar=iTime(NULL,tf,0); if(barsSumm>=0 && barsSummcurTimeBar) return startTime + addBars * periodSeconds; if(barsSumm<0) return curTimeBar + (-barsSumm) * periodSeconds; return iTime(NULL, tf, barsCount - 1); } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ //| Finding the bar at current TF with specified extremum type and returning it opening time | //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ datetime GetExtremumTimeAtCurrentTF(datetime startTime,datetime endTime,int mode) { int startBarIndex=iBarShift(NULL,PERIOD_CURRENT,startTime); int endBarIndex=-1; if(endTime<=iTime(NULL,PERIOD_CURRENT,0)) endBarIndex=iBarShift(NULL,PERIOD_CURRENT,endTime); double extPrice = 0.0; int extBarIndex = -1; for(int i=startBarIndex; i>endBarIndex; i--) { if(mode==MODE_HIGH && iHigh(NULL,PERIOD_CURRENT,i)>extPrice) { extBarIndex=i; extPrice=iHigh(NULL,PERIOD_CURRENT,i); } if(mode==MODE_LOW && (iLow(NULL,PERIOD_CURRENT,i)=0; barIndex--) for(int tfIndex=0; tfIndex