2
Views
0
Downloads
0
Favorites
Fibo_Independence
//+------------------------------------------------------------------+
//| Fibo_Independence.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 = "Fib1"; // 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_236_Show = false;
extern bool Fibo_382_Show = true;
extern bool Fibo_500_Show = false;
extern bool Fibo_618_Show = true;
extern bool Fibo_707_Show = false;
extern bool Fibo_786_Show = true;
extern bool Fibo_886_Show = true;
extern string Note2 = "Select line colors";
extern color Fibo_0_Color = DimGray;
extern color Fibo_236_Color = Khaki;
extern color Fibo_382_Color = Red;
extern color Fibo_500_Color = FireBrick;
extern color Fibo_618_Color = Blue;
extern color Fibo_707_Color = Magenta;
extern color Fibo_786_Color = DarkViolet;
extern color Fibo_886_Color = Green;
extern color Fibo_100_Color = DimGray;
extern string Note3 = "Select line width";
extern string Note4 = "setting 0 - 4";
extern int Fibo_0_Width = 0;
extern int Fibo_236_Width = 0;
extern int Fibo_382_Width = 1;
extern int Fibo_500_Width = 0;
extern int Fibo_618_Width = 1;
extern int Fibo_707_Width = 0;
extern int Fibo_786_Width = 0;
extern int Fibo_886_Width = 0;
extern int Fibo_100_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_236_Style = 1;
extern int Fibo_382_Style = 0;
extern int Fibo_500_Style = 1;
extern int Fibo_618_Style = 0;
extern int Fibo_707_Style = 1;
extern int Fibo_786_Style = 0;
extern int Fibo_886_Style = 0;
extern int Fibo_100_Style = 1;
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
ClearChart();
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
//+---------------------+
//| Fibo lines function |
//+---------------------+
double FIBO100,FIBO0,Q,FIBO236,FIBO382,FIBO50,FIBO618,FIBO707,FIBO786,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(T1<T2 && price1<price2)
{
FIBO100=price1;
FIBO0=price2;
Q=MathAbs(FIBO100-FIBO0);
FIBO236=FIBO0-(Q*0.236);
FIBO382=FIBO0-(Q*0.382);
FIBO50=FIBO0-(Q*0.5);
FIBO618=FIBO0-(Q*0.618);
FIBO707=FIBO0-(Q*0.707);
FIBO786=FIBO0-(Q*0.786);
FIBO886=FIBO0-(Q*0.886);
}
else
{
FIBO100=price1;
FIBO0=price2;
Q=FIBO100-FIBO0;
FIBO236=FIBO0+(Q*0.236);
FIBO382=FIBO0+(Q*0.382);
FIBO50=FIBO0+(Q*0.5);
FIBO618=FIBO0+(Q*0.618);
FIBO707=FIBO0+(Q*0.707);
FIBO786=FIBO0+(Q*0.786);
FIBO886=FIBO0+(Q*0.886);
}
//---- Fibo Lines ----//
string gap = " "; // spaces in the text string
string gap2 = " ";
TextBarsAhead = BarsAhead + textadd; // makes one number from 2 for display calculation
if(HighBarsBack>LowBarsBack){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_236_Show) Text("FIB236 label" + TrendName,0, gap+ TrendName+ " 23.6%"+ gap2+ DoubleToStr(FIBO236,Digits), TextSize,TextFont, Fibo_236_Color, (Time[0]+TextBarsAhead*Period()*60), FIBO236,true);
if(Fibo_382_Show) Text("FIB382 label" + TrendName,0, gap+ TrendName+ " 38.2%"+ gap2+ DoubleToStr(FIBO382,Digits), TextSize,TextFont, Fibo_382_Color, (Time[0]+TextBarsAhead*Period()*60), FIBO382,true);
if(Fibo_500_Show) Text("FIB50 label" + TrendName,0, gap+ TrendName+ " 50.0%"+ gap2+ DoubleToStr(FIBO50,Digits), TextSize,TextFont, Fibo_500_Color, (Time[0]+TextBarsAhead*Period()*60), FIBO50,true);
if(Fibo_618_Show) Text("FIB618 label" + TrendName,0, gap+ TrendName+ " 61.8%"+ gap2+ DoubleToStr(FIBO618,Digits), TextSize,TextFont, Fibo_618_Color, (Time[0]+TextBarsAhead*Period()*60), FIBO618,true);
if(Fibo_707_Show) Text("FIB707 label" + TrendName,0, gap+ TrendName+ " 70.7%"+ gap2+ DoubleToStr(FIBO707,Digits), TextSize,TextFont, Fibo_707_Color, (Time[0]+TextBarsAhead*Period()*60), FIBO707,true);
if(Fibo_786_Show) Text("FIB786 label" + TrendName,0, gap+ TrendName+ " 78.6%"+ gap2+ DoubleToStr(FIBO786,Digits), TextSize,TextFont, Fibo_786_Color, (Time[0]+TextBarsAhead*Period()*60), FIBO786,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_236_Show) Level("FIB236 line" + TrendName,0, FIBO236, FIBO236, Time[length], Fibo_236_Width, Fibo_236_Style, Fibo_236_Color,true);
if(Fibo_382_Show) Level("FIB382 line" + TrendName,0, FIBO382, FIBO382, Time[length], Fibo_382_Width, Fibo_382_Style, Fibo_382_Color,true);
if(Fibo_500_Show) Level("FIB50 line" + TrendName,0, FIBO50, FIBO50, Time[length], Fibo_500_Width, Fibo_500_Style, Fibo_500_Color,true);
if(Fibo_618_Show) Level("FIB618 line" + TrendName,0, FIBO618, FIBO618, Time[length], Fibo_618_Width, Fibo_618_Style, Fibo_618_Color, true);
if(Fibo_707_Show) Level("FIB707 line" + TrendName,0, FIBO707, FIBO707, Time[length], Fibo_707_Width, Fibo_707_Style, Fibo_707_Color, true);
if(Fibo_786_Show) Level("FIB786 line" + TrendName,0, FIBO786, FIBO786, Time[length], Fibo_786_Width, Fibo_786_Style, Fibo_786_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_236_Show) Level("FIB236 line" + TrendName,0, FIBO236, FIBO236, Time[length], Fibo_236_Width, Fibo_236_Style, Fibo_236_Color, true);
if(Fibo_382_Show) Level("FIB382 line" + TrendName,0, FIBO382, FIBO382, Time[length], Fibo_382_Width, Fibo_382_Style, Fibo_382_Color, true);
if(Fibo_500_Show) Level("FIB50 line" + TrendName,0, FIBO50, FIBO50, Time[length], Fibo_500_Width, Fibo_500_Style, Fibo_500_Color, true);
if(Fibo_618_Show) Level("FIB618 line" + TrendName,0, FIBO618, FIBO618, Time[length], Fibo_618_Width, Fibo_618_Style, Fibo_618_Color, true);
if(Fibo_707_Show) Level("FIB707 line" + TrendName,0, FIBO707, FIBO707, Time[length], Fibo_707_Width, Fibo_707_Style, Fibo_707_Color, true);
if(Fibo_786_Show) Level("FIB786 line" + TrendName,0, FIBO786, FIBO786, Time[length], Fibo_786_Width, Fibo_786_Style, Fibo_786_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);
}
void Level(string Levels, int Window, double start, double end, double time, double w, double s, color clr, bool delete)
{
if (delete) 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));
}
void Text(string TextName, int Window, string LabelText, int FontSize, string FontName, color TextColor, datetime Time1, double Price1, bool delete)
{
if (delete) 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);
}
void ClearChart()
{
ObjectDelete("FIB100 Label" + TrendName);
ObjectDelete("FIB100 Line" + TrendName);
ObjectDelete("FIB0 Label" + TrendName);
ObjectDelete("FIB0 Line" + TrendName);
ObjectDelete("FIB236 Label" + TrendName);
ObjectDelete("FIB236 Line" + TrendName);
ObjectDelete("FIB382 Label" + TrendName);
ObjectDelete("FIB382 Line" + TrendName);
ObjectDelete("FIB50 Label" + TrendName);
ObjectDelete("FIB50 Line" + TrendName);
ObjectDelete("FIB618 Label" + TrendName);
ObjectDelete("FIB618 Line" + TrendName);
ObjectDelete("FIB707 Label" + TrendName);
ObjectDelete("FIB707 Line" + TrendName);
ObjectDelete("FIB786 Line" + TrendName);
ObjectDelete("FIB786 Label" + TrendName);
ObjectDelete("FIB886 Line" + TrendName);
ObjectDelete("FIB886 Label" + TrendName);
return;
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---