//+------------------------------------------------------------------+ //| DF-DonchianFibo.mq4 | //| Copyright 2014, DonForex | //| http://donforex.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, DonForex" #property link "https://www.forexfactory.com/thread/594890-indicator-bank?page=105" //"https://www.forexfactory.com/forum/69-platform-tech" #property description "DonForex - DonchianFibo indicator" #property version "3.87" //"1.01" #property strict //---- indicator settings #property indicator_chart_window #property indicator_buffers 7 //--- #property indicator_color1 clrOrchid #property indicator_color2 clrDarkOrange #property indicator_color3 clrChartreuse #property indicator_color4 clrSteelBlue #property indicator_color5 clrChartreuse #property indicator_color6 clrDarkOrange #property indicator_color7 clrOrchid //--- #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_width6 1 #property indicator_width7 1 //--- #property indicator_style1 STYLE_SOLID #property indicator_style2 STYLE_DOT #property indicator_style3 STYLE_DOT #property indicator_style4 STYLE_DOT #property indicator_style5 STYLE_DOT #property indicator_style6 STYLE_DOT #property indicator_style7 STYLE_SOLID //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ //0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711; //0.1454, 0.236, 0.382, 0.5, 0.618, 0.786, 1.0, 1.272, 1.414, 1.618, 2.058, 2.618, 3.32, 4.236, 5.35, 6.853.... //---- indicator parameters extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; extern string Copyright = "http://donforex.com"; extern int DFPeriod = 55; //Donchian Period extern ENUM_STO_PRICE DFPrice = STO_LOWHIGH; //Donchian Price extern double Coef236 = 0.236, Coef382 = 0.382, Coef500 = 0.500, Coef618 = 0.618, Coef764 = 0.764; extern bool ShowPrices = true; //Show Prices extern color ColorLowest = clrOrchid; extern color Color236 = clrDarkOrange; extern color Color382 = clrChartreuse; extern color Color500 = clrSteelBlue; extern color Color618 = clrChartreuse; extern color Color764 = clrDarkOrange; extern color ColorHighest = clrOrchid; extern int buttSize = 10; //Button text width extern color buttColor = clrLime; //Button text color extern color backColor = clrMediumVioletRed; //Button background color extern int axisX = 0; //Button X axis extern int axisY = 387; //Button Y axis extern ENUM_BASE_CORNER buttCorner = CORNER_LEFT_UPPER; //Button base corner extern int buttWindow = 0; //Button in which window extern string buttName = "DONFIBO"; //Button text //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #define CallMTF(BUFF,idx) iCustom(NULL,TimeFrame,IndukName, TimeFrame,Copyright,DFPeriod,DFPrice,Coef236,Coef382,Coef500,Coef618,Coef764,ShowPrices,ColorLowest,Color236,Color382,Color500,Color618,Color764,ColorHighest, BUFF, idx) //---- indicator buffers double LOWEST[]; double BUF236[]; double BUF382[]; double BUF500[]; double BUF618[]; double BUF764[]; double HIGEST[]; double Diff; //--- int MAX, TFK, MTK, ARB, SGB, TikKont=2, ReCalc=1; string sTFR, cTFR, TWIN, IndukName; datetime TimeBar=0, NewTime=0, OneTime=0; bool boBand=false, boHist=false, yesBars=false; //--- string sName, ShortName = "["+(string)DFPeriod+StringSubstr(EnumToString(DFPrice),3)+"]"; //+"±"+ //--- string PREF = "DF"+DoubleToString(sqrt((Coef236+Coef382+Coef500+Coef618+Coef764)/5),3)+ShortName; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { TimeFrame = fmax(TimeFrame,_Period); TFK = TimeFrame/_Period; sTFR = StringSubstr(EnumToString(TimeFrame),7); cTFR = StringSubstr(EnumToString(ENUM_TIMEFRAMES(_Period)),7); IndukName = WindowExpertName(); //--- DFPeriod = fmax(DFPeriod,1); //Percent = fmax(1,fmin(Percent,999)); //--- MTK = TFK; MAX = DFPeriod+MTK; //---- drawing settings IndicatorBuffers(7); IndicatorSetInteger(INDICATOR_DIGITS,(int)SymbolInfoInteger(NULL,SYMBOL_DIGITS)); //Digits-Digits%2); //--- SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_LINE); SetIndexStyle(3,DRAW_LINE); SetIndexStyle(4,DRAW_LINE); SetIndexStyle(5,DRAW_LINE); SetIndexStyle(6,DRAW_LINE); //---- indicator buffers mapping SetIndexBuffer(0,LOWEST); SetIndexBuffer(1,BUF236); SetIndexBuffer(2,BUF382); SetIndexBuffer(3,BUF500); SetIndexBuffer(4,BUF618); SetIndexBuffer(5,BUF764); SetIndexBuffer(6,HIGEST); //---- name for DataWindow and indicator subwindow label IndicatorShortName(sTFR+": DonFibo "+ShortName); //--- SetIndexLabel(0,sTFR+": LOWEST"); SetIndexLabel(1,Coef236!=0 ? sTFR+": BUF236 * "+DoubleToString(Coef236,3) : NULL); SetIndexLabel(2,Coef382!=0 ? sTFR+": BUF382 * "+DoubleToString(Coef382,3) : NULL); SetIndexLabel(3,Coef500!=0 ? sTFR+": BUF500 * "+DoubleToString(Coef500,3) : NULL); SetIndexLabel(4,Coef618!=0 ? sTFR+": BUF618 * "+DoubleToString(Coef618,3) : NULL); SetIndexLabel(5,Coef764!=0 ? sTFR+": BUF764 * "+DoubleToString(Coef764,3) : NULL); SetIndexLabel(6,sTFR+": HIGEST"); //------ рисуем Кнопку if (ObjectFind(0,PrefBT)<0) DrawBUTTON(0,PrefBT,buttName,buttColor,backColor,winTotal,true); ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,1); //EventSetTimer(1); /* PLEASE, DON'T REMOVE IT!*/ Comment(StringConcatenate(sTFR+": DF-DonchianFibo ",ShortName," >> http://donforex.com")); /* PLEASE, DON'T REMOVE IT!*/ if (ShowPrices) { ObjectCreate(PREF+"lb1",OBJ_ARROW,0,Time[0],Close[0]); ObjectSet(PREF+"lb1",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE); ObjectSet(PREF+"lb1",OBJPROP_COLOR,ColorLowest); ObjectCreate(PREF+"lb2",OBJ_ARROW,0,Time[0],Close[0]); ObjectSet(PREF+"lb2",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE); ObjectSet(PREF+"lb2",OBJPROP_COLOR,Color236); ObjectCreate(PREF+"lb3",OBJ_ARROW,0,Time[0],Close[0]); ObjectSet(PREF+"lb3",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE); ObjectSet(PREF+"lb3",OBJPROP_COLOR,Color382); ObjectCreate(PREF+"lb4",OBJ_ARROW,0,Time[0],Close[0]); ObjectSet(PREF+"lb4",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE); ObjectSet(PREF+"lb4",OBJPROP_COLOR,Color500); ObjectCreate(PREF+"lb5",OBJ_ARROW,0,Time[0],Close[0]); ObjectSet(PREF+"lb5",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE); ObjectSet(PREF+"lb5",OBJPROP_COLOR,Color618); ObjectCreate(PREF+"lb6",OBJ_ARROW,0,Time[0],Close[0]); ObjectSet(PREF+"lb6",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE); ObjectSet(PREF+"lb6",OBJPROP_COLOR,Color764); ObjectCreate(PREF+"lb7",OBJ_ARROW,0,Time[0],Close[0]); ObjectSet(PREF+"lb7",OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE); ObjectSet(PREF+"lb7",OBJPROP_COLOR,ColorHighest); } //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ //int deinit() { Comment(""); ObjectsDeleteAll(0,PREF,-1,-1); return(0); } void OnDeinit(const int reason) { Comment(""); ObjectsDeleteAll(0,PREF,-1,-1); //EventKillTimer(); //--- switch(reason) { //case REASON_PARAMETERS : case REASON_CHARTCHANGE : case REASON_RECOMPILE : case REASON_CLOSE : break; default : ObjectDelete(0,PrefBT); } } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { if (buttYes && objSTATE(PrefBT)=="OFF") return(0); //TikKont++; //if (TikKont%4==0) { //--- int counted_bars=IndicatorCounted(); //---- check for possible errors if (counted_bars<0) return(-1); //---- the last counted bar will be recounted if (counted_bars>0) counted_bars--; int minBars=fmin(iBars(NULL,0),fmin(iBars(NULL,TimeFrame),iBars(NULL,TimeFrame))); int limit = (counted_bars>0 && ReCalc>0) ? iBars(NULL,0)-counted_bars-1+MTK : minBars-3-MAX; //Bars-counted_bars; //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ if (TimeFrame!=_Period) { limit = (int)fmax(limit,fmin(iBars(NULL,0)-3,CallMTF(7,0)*MTK)); //Comment( CallMTF(9,0)*TimeFrame/_Period ); //--- for (int i=limit; i>=0; i--) { int y = iBarShift(NULL,TimeFrame,iTime(NULL,0,i),false); //int x = y; x = iBarShift(TWIN,TimeFrame,iTime(TWIN,0,i+1)); //--- LOWEST[i] = CallMTF(0,y); BUF236[i] = CallMTF(1,y); BUF382[i] = CallMTF(2,y); BUF500[i] = CallMTF(3,y); BUF618[i] = CallMTF(4,y); BUF764[i] = CallMTF(5,y); HIGEST[i] = CallMTF(6,y); //--- //if (x!=y) { ARRBU[i] = CallMTF(5,y); ARRSE[i] = CallMTF(6,y); } //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ } //*конец цикла* for (i=limit; i>=0; i--) //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ return(0); } //*конец* if (TimeFrame!=_Period)..... //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //---- calculate values if (DFPrice==0) { for (int i=0; iHighestValue) { HighestValue = MathMax(Open[w+i],Close[w+i]); HighestBodyIndex = w+i; } } } HIGEST[i]=0; HIGEST[i] = MathMax(Open[HighestBodyIndex],Close[HighestBodyIndex]); int LowestBodyIndex = 0; double LowestValue = 9999999; for (int w=0; w",ShowSupRes,"]"); //StringConcatenate("iSRSSR[",axisX,"x",axisY,"]","but"); //= "a"+PREF+"but"; //"bAKHR"+ShortName; //------ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if (id==CHARTEVENT_OBJECT_CLICK && sparam==PrefBT) getOnOff(0,PrefBT); //--- if (id==CHARTEVENT_CHART_CHANGE && buttYes && objSTATE(PrefBT)=="OFF") return; //костыль против инициализации индюка при переключении ТФ... //--- //if (buttON[0]!="OFF" && id==CHARTEVENT_CHART_CHANGE && boHist) { start(); /*ChartSetInteger(0,CHART_FOREGROUND,0,false);*/ DrawHistoLine(); ChartRedraw(0); } //--- if (id==CHARTEVENT_CHART_CHANGE && winTotal!=WindowsTotal()-1) { winTotal = WindowsTotal()-1; DrawBUTTON(0,PrefBT,buttName, (buttON[0]!="OFF"?buttColor:clrBlack), backColor,winTotal, (buttON[0]!="OFF"?true:false)); ChartRedraw(0); } } //**************************************************************************** //*** CastIron PriceAction *** //**************************************************************************** string objSTATE(string Name) { return( ObjectGetInteger(0,Name,OBJPROP_STATE) ? "ON" : "OFF" ); } //**************************************************************************** //*** Akomuto Hirovato *** //**************************************************************************** void getOnOff(int NB, string Name) { buttON[NB] = objSTATE(Name); if (buttON[NB]!=preState[NB]) if (buttON[NB]=="OFF") { InitZero(NB); ObjectSetInteger(0,Name,OBJPROP_COLOR, clrBlack); preState[NB] = buttON[NB]; ChartRedraw(0); } else { init(); TikKont=2; NewTime=0; OneTime=0; ReCalc=0; start(); ObjectSetInteger(0,Name,OBJPROP_COLOR, buttColor); preState[NB] = buttON[NB]; ChartRedraw(0); } } //**************************************************************************** //*** MA 2Smoothed AA MTF TT *** //**************************************************************************** bool buttYes = buttColor!=clrNONE && buttSize>4; int winTotal=0; double bLen=fmax(1,StringLen(buttName)*1.15); bool DrawBUTTON(int NB, string Name, string Text, color txtClr=clrWhite, color bckClr=clrBlack, int winTot=0, bool OnOff=false) { if (buttColor==clrNONE || buttSize<5) return(false); //--- string objName = Name; //PREF+ //+(string)i; //+TimeToStr(Time[i],TIME_MINUTES)+"_"+(string)Close[i],DGTS); //--- пред-удаление обектов ObjectDelete(0,objName); //Comment( (string)bLen ); //--- создадим кнопку if (!ObjectCreate(0,objName,OBJ_BUTTON, fmax(0,fmin(buttWindow,winTot)), 0, 0)) return(false); //--- установим координаты кнопки double XX = (buttCorner==0||buttCorner==2) ? 5+axisX : 10*buttSize/1.35+axisX; double YY = (5+axisY)+buttSize*2.25*NB; ObjectSetInteger(0,objName,OBJPROP_XDISTANCE, (int)XX); // координата по оси X ObjectSetInteger(0,objName,OBJPROP_YDISTANCE, (int)YY); // координата по оси Y ObjectSetInteger(0,objName,OBJPROP_XSIZE, int(buttSize*bLen)); // ширина кнопки //133 ObjectSetInteger(0,objName,OBJPROP_YSIZE, int(buttSize*2.0)); // высота кнопки //33 ObjectSetInteger(0,objName,OBJPROP_CORNER, buttCorner); // угол графика для привязки кнопки //CORNER_LEFT_UPPER ObjectSetString (0,objName,OBJPROP_TEXT, Text); // текст ObjectSetString (0,objName,OBJPROP_FONT, "Arial Black"); // шрифт ObjectSetInteger(0,objName,OBJPROP_FONTSIZE, buttSize); // размер шрифта ObjectSetInteger(0,objName,OBJPROP_COLOR, txtClr); // цвет текста ObjectSetInteger(0,objName,OBJPROP_BGCOLOR, bckClr); // цвет фона //C'236,233,216' ObjectSetInteger(0,objName,OBJPROP_BORDER_COLOR, clrNONE); // цвет границы ObjectSetInteger(0,objName,OBJPROP_BACK, false); // на заднем плане ObjectSetInteger(0,objName,OBJPROP_SELECTABLE, false); // кнопку можно выделить ObjectSetInteger(0,objName,OBJPROP_SELECTED, false); // выделить для перемещений ObjectSetInteger(0,objName,OBJPROP_HIDDEN, false); // скрыт в списке объектов ObjectSetInteger(0,objName,OBJPROP_ZORDER, 0); // приоритет на нажатие мышью ObjectSetInteger(0,objName,OBJPROP_STATE, OnOff); // кнопка нажата/отжата //--- успешное выполнение return(true); } //**************************************************************************** //*** ATRMA Levels MTF TT *** //**************************************************************************** void InitZero(int NB) { Comment(""); //--- ArrayInitialize(LOWEST,0.0); ArrayInitialize(BUF236,0.0); ArrayInitialize(BUF382,0.0); ArrayInitialize(BUF500,0.0); ArrayInitialize(BUF618,0.0); ArrayInitialize(BUF764,0.0); ArrayInitialize(HIGEST,0.0); //for (int i=0; i