//+------------------------------------------------------------------+ //| Fibo_Independence E.mq4 | //| Copyright © 2012, bdeyes | //| bdeyes357@yahoo.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2012, bdeyes" #property link "bdeyes357@yahoo.com" #property indicator_chart_window /* To use: Place indicator on your chart. Setting "TrendName" to unique value will allow the running of multiple copies of the indicator. (this allows you to use multiple fibs at the same time to look for areas of confluence) Draw a trendline where you want the fibonacci levels calculated (same as you would to use the MT4 fib retracement tool). Open the trendline properties box and name the trendline the same as the name at TrendName - i.e. "Fib1". Fib levels will calculate on next tick or you can refresh your chart. To make changes open the indicator properties box and make adjustments You can choose which levels to display, what color the lines are, what width the lines are, and what style the lines are all without redrawing the fib. To make any of the settings the "default" make changes in MetaEditor and then compile the indicator again. To make multiple settings for multiple TrendNames, make your settings and then save everything as a template. */ // -------- External Variables --------------------------------------+ extern string TrendName="FibE1"; // Unique name of trend line to place fib on. extern string Note1="Set \"true\" to show line"; extern bool Fibo_0_Show=true; extern bool Fibo_100_Show=true; extern bool Fibo_1272_Show = false; extern bool Fibo_1414_Show = true; extern bool Fibo_1618_Show = true; extern bool Fibo_2000_Show = false; extern bool Fibo_2618_Show = true; //extern bool Fibo_886_Show = true; extern string Note2="Select line colors"; extern color Fibo_0_Color = DimGray; extern color Fibo_100_Color = DimGray; extern color Fibo_1272_Color = Khaki; extern color Fibo_1414_Color = Red; extern color Fibo_1618_Color = Blue; extern color Fibo_2000_Color = Magenta; extern color Fibo_2618_Color = DarkViolet; //extern color Fibo_886_Color = Green; extern string Note3 = "Select line width"; extern string Note4 = "setting 0 - 4"; extern int Fibo_0_Width = 0; extern int Fibo_100_Width = 0; extern int Fibo_1272_Width = 0; extern int Fibo_1414_Width = 1; extern int Fibo_1618_Width = 1; extern int Fibo_2000_Width = 0; extern int Fibo_2618_Width = 0; //extern int Fibo_886_Width = 0; extern string Note5 = "Select line style"; extern string Note6 = "setting 0 = solid"; extern string Note7 = "setting 1 = dash"; extern string Note8 = "setting 2 = dot"; extern string Note9 = "setting 3 = dashdot"; extern string Note10 = "setting 4 = dashdotdot"; extern string Note11 = "Only works with"; extern string Note12 = "line width > 2"; extern int Fibo_0_Style = 1; extern int Fibo_100_Style = 1; extern int Fibo_1272_Style = 1; extern int Fibo_1414_Style = 0; extern int Fibo_1618_Style = 0; extern int Fibo_2000_Style = 1; extern int Fibo_2618_Style = 0; //extern int Fibo_886_Style = 0; extern int TextSize=10; // text size for price & fib number extern string TextFont="Arial"; //text to use for display font extern string Note0="To extend line beyond of price"; extern int BarsAhead=12; // Number of bars ahead of current price to show line & text int TextBarsAhead=0; int textadd=5; // move text off end of line this many bars //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicator short name IndicatorShortName("Fibo_Independence"+TrendName); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { ClearChart(); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //+---------------------+ //| Fibo lines function | //+---------------------+ double FIBO100,FIBO0,Q,FIBO1272,FIBO1414,FIBO50,FIBO1618,FIBO2000,FIBO2618;//,FIBO886; double WaveStart,WaveEnd; double price1=0,price2=0; datetime T1,T2; int HighBarsBack= 0; int LowBarsBack = 0; if(ObjectType(TrendName)==OBJ_TREND) { price1=ObjectGet(TrendName,OBJPROP_PRICE1); T1=ObjectGet(TrendName,OBJPROP_TIME1); price2=ObjectGet(TrendName,OBJPROP_PRICE2); T2=ObjectGet(TrendName,OBJPROP_TIME2); LowBarsBack=iBarShift(NULL,0,T2); HighBarsBack=iBarShift(NULL,0,T1); } else { ClearChart(); return(0); } if(T1LowBarsBack){int length=HighBarsBack;}else{length=LowBarsBack;} if(Fibo_100_Show) Text("FIB100 label"+TrendName,0,gap+TrendName+" 100.0%"+gap2+DoubleToStr(FIBO100,Digits),TextSize,TextFont,Fibo_100_Color,(Time[0]+TextBarsAhead*Period()*60),FIBO100,true); if(Fibo_0_Show) Text("FIB0 label"+TrendName,0,gap+TrendName+" 0.0%"+gap2+DoubleToStr(FIBO0,Digits),TextSize,TextFont,Fibo_0_Color,(Time[0]+TextBarsAhead*Period()*60),FIBO0,true); if(Fibo_1272_Show) Text("FIB1272 label"+TrendName,0,gap+TrendName+" 127.2%"+gap2+DoubleToStr(FIBO1272,Digits),TextSize,TextFont,Fibo_1272_Color,(Time[0]+TextBarsAhead*Period()*60),FIBO1272,true); if(Fibo_1414_Show) Text("FIB1414 label"+TrendName,0,gap+TrendName+" 141.4%"+gap2+DoubleToStr(FIBO1414,Digits),TextSize,TextFont,Fibo_1414_Color,(Time[0]+TextBarsAhead*Period()*60),FIBO1414,true); if(Fibo_1618_Show) Text("FIB1618 label"+TrendName,0,gap+TrendName+" 161.8%"+gap2+DoubleToStr(FIBO1618,Digits),TextSize,TextFont,Fibo_1618_Color,(Time[0]+TextBarsAhead*Period()*60),FIBO1618,true); if(Fibo_2000_Show) Text("FIB2000 label"+TrendName,0,gap+TrendName+" 200.0%"+gap2+DoubleToStr(FIBO2000,Digits),TextSize,TextFont,Fibo_2000_Color,(Time[0]+TextBarsAhead*Period()*60),FIBO2000,true); if(Fibo_2618_Show) Text("FIB2618 label"+TrendName,0,gap+TrendName+" 261.8%"+gap2+DoubleToStr(FIBO2618,Digits),TextSize,TextFont,Fibo_2618_Color,(Time[0]+TextBarsAhead*Period()*60),FIBO2618,true); //if(Fibo_886_Show) Text("FIB886 label" + TrendName,0, gap+ TrendName+ " 88.6%"+ gap2+ DoubleToStr(FIBO886,Digits), TextSize,TextFont, Fibo_886_Color, (Time[0]+TextBarsAhead*Period()*60), FIBO886,true); //------------------------------------------------------------ if(HighBarsBack>LowBarsBack) { if(Fibo_100_Show) Level("FIB100 line"+TrendName,0,FIBO100,FIBO100,Time[length],Fibo_100_Width,Fibo_100_Style,Fibo_100_Color,true); if(Fibo_0_Show) Level("FIB0 line"+TrendName,0,FIBO0,FIBO0,Time[length],Fibo_0_Width,Fibo_0_Style,Fibo_0_Color,true); if(Fibo_1272_Show) Level("FIB1272 line"+TrendName,0,FIBO1272,FIBO1272,Time[length],Fibo_1272_Width,Fibo_1272_Style,Fibo_1272_Color,true); if(Fibo_1414_Show) Level("FIB1414 line"+TrendName,0,FIBO1414,FIBO1414,Time[length],Fibo_1414_Width,Fibo_1414_Style,Fibo_1414_Color,true); if(Fibo_1618_Show) Level("FIB1618 line"+TrendName,0,FIBO1618,FIBO1618,Time[length],Fibo_1618_Width,Fibo_1618_Style,Fibo_1618_Color,true); if(Fibo_2000_Show) Level("FIB2000 line"+TrendName,0,FIBO2000,FIBO2000,Time[length],Fibo_2000_Width,Fibo_2000_Style,Fibo_2000_Color,true); if(Fibo_2618_Show) Level("FIB2618 line"+TrendName,0,FIBO2618,FIBO2618,Time[length],Fibo_2618_Width,Fibo_2618_Style,Fibo_2618_Color,true); //if(Fibo_886_Show) Level("FIB886 line" + TrendName,0, FIBO886, FIBO886, Time[length], Fibo_886_Width, Fibo_886_Style, Fibo_886_Color, true); } else { if(Fibo_100_Show) Level("FIB100 line"+TrendName,0,FIBO100,FIBO100,Time[length],Fibo_100_Width,Fibo_100_Style,Fibo_100_Color,true); if(Fibo_0_Show) Level("FIB0 line"+TrendName,0,FIBO0,FIBO0,Time[length],Fibo_0_Width,Fibo_0_Style,Fibo_0_Color,true); if(Fibo_1272_Show) Level("FIB1272 line"+TrendName,0,FIBO1272,FIBO1272,Time[length],Fibo_1272_Width,Fibo_1272_Style,Fibo_1272_Color,true); if(Fibo_1414_Show) Level("FIB1414 line"+TrendName,0,FIBO1414,FIBO1414,Time[length],Fibo_1414_Width,Fibo_1414_Style,Fibo_1414_Color,true); if(Fibo_1618_Show) Level("FIB1618 line"+TrendName,0,FIBO1618,FIBO1618,Time[length],Fibo_1618_Width,Fibo_1618_Style,Fibo_1618_Color,true); if(Fibo_2000_Show) Level("FIB2000 line"+TrendName,0,FIBO2000,FIBO2000,Time[length],Fibo_2000_Width,Fibo_2000_Style,Fibo_2000_Color,true); if(Fibo_2618_Show) Level("FIB2618 line"+TrendName,0,FIBO2618,FIBO2618,Time[length],Fibo_2618_Width,Fibo_2618_Style,Fibo_2618_Color,true); //if(Fibo_886_Show) Level("FIB886 line" + TrendName,0, FIBO886, FIBO886, Time[length], Fibo_886_Width, Fibo_886_Style, Fibo_886_Color, true); } return(0); } //+------------------------------------------------------------------+ //| Level | //+------------------------------------------------------------------+ void Level(string Levels,int Window,double start,double end,double time,double w,double s,color clr,bool del) { if(del) ObjectDelete(Levels); if(ObjectFind(Levels)!=0) { ObjectCreate(Levels,OBJ_TREND,0,0,start,(Time[0]+BarsAhead*Period()*60),end); ObjectSet(Levels,OBJPROP_COLOR,clr); ObjectSet(Levels,OBJPROP_RAY,false); ObjectSet(Levels,OBJPROP_BACK,true); ObjectSet(Levels,OBJPROP_WIDTH,w); ObjectSet(Levels,OBJPROP_STYLE,s); ObjectSet(Levels,OBJPROP_TIME1,time); } else ObjectMove(Levels,0,0,(Time[0]+BarsAhead*Period()*60)); } //+------------------------------------------------------------------+ //| Text | //+------------------------------------------------------------------+ void Text(string TextName,int Window,string LabelText,int FontSize,string FontName,color TextColor,datetime Time1,double Price1,bool del) { if(del) ObjectDelete(TextName); if(ObjectFind(TextName)!=0) { ObjectCreate(TextName,OBJ_TEXT,Window,Time1,Price1); ObjectSetText(TextName,LabelText,FontSize,FontName,TextColor); ObjectSet(TextName,OBJPROP_BACK,true); } else ObjectMove(TextName,0,Time1,Price1); } //+------------------------------------------------------------------+ //| ClearChart | //+------------------------------------------------------------------+ void ClearChart() { ObjectDelete("FIB100 Label"+TrendName); ObjectDelete("FIB100 Line"+TrendName); ObjectDelete("FIB0 Label"+TrendName); ObjectDelete("FIB0 Line"+TrendName); ObjectDelete("FIB1272 Label"+TrendName); ObjectDelete("FIB1272 Line"+TrendName); ObjectDelete("FIB1414 Label"+TrendName); ObjectDelete("FIB1414 Line"+TrendName); ObjectDelete("FIB1618 Label"+TrendName); ObjectDelete("FIB1618 Line"+TrendName); ObjectDelete("FIB2000 Label"+TrendName); ObjectDelete("FIB2000 Line"+TrendName); ObjectDelete("FIB2618 Line"+TrendName); ObjectDelete("FIB2618 Label"+TrendName); //ObjectDelete("FIB886 Line" + TrendName); //ObjectDelete("FIB886 Label" + TrendName); return; } //+------------------------------------------------------------------+