0
Views
0
Downloads
0
Favorites
BoxFibo
//+------------------------------------------------------------------+
//| BoxFibo.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
extern string StartTime = "04:00"; // time for start of price establishment window
extern string EndTime = "07:15"; // time for end of price establishment window
extern int NumDays = 2;
extern color BoxColor = LightGray;
extern color FiboColor = Black;
//+------------------------------------------------------------------+
int init() {
//+------------------------------------------------------------------+
del_obj();
return(0);
}
//+------------------------------------------------------------------+
int deinit() {
//+------------------------------------------------------------------+
del_obj();
return(0);
}
//+------------------------------------------------------------------+
void start() {
//+------------------------------------------------------------------+
datetime dt1 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + StartTime + ":00");
datetime dt2 = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + EndTime + ":00");
int dys = 0, NumBars = (dt2-dt1)/60/Period();
for (int i=0; i< NumDays * 96 /*Bars-NumBars */; i++)
{
dt1 = StrToTime(TimeToStr(Time[i],TIME_DATE) + " " + StartTime + ":00");
dt2 = StrToTime(TimeToStr(Time[i],TIME_DATE) + " " + EndTime + ":00");
int ib1 = iBarShift(NULL,0,dt1);
int ib2 = iBarShift(NULL,0,dt2);
if (dt2 != Time[i]) continue;
double vHigh = 0, vLow = 999;
for (int j=ib1; j>ib2; j--) {
vHigh = MathMax(vHigh,High[j]);
vLow = MathMin(vLow,Low[j]);
}
string objname = "BF-Box-" + i;
ObjectCreate(objname,OBJ_RECTANGLE,0,dt1,vHigh,dt2-60,vLow);
ObjectSet(objname,OBJPROP_COLOR,BoxColor);
objname = "BF-Fibo-" + i;
ObjectCreate(objname,OBJ_FIBO,0,dt2-7200,vHigh,dt2,vLow);
ObjectSet(objname,OBJPROP_RAY,false);
ObjectSet(objname,OBJPROP_COLOR,BoxColor);
ObjectSet(objname,OBJPROP_LEVELCOLOR,FiboColor);
ObjectSet(objname,OBJPROP_FIBOLEVELS,15);
ObjectSet(objname,OBJPROP_LEVELSTYLE,STYLE_SOLID);
ObjectSet(objname,OBJPROP_FIRSTLEVEL,0.0);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+1,0.5);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+2,1.0);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+3,-0.236);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+4,-0.382);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+5,-0.618);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+6,-1.0);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+7,1.236);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+8,1.382);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+9,1.618);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+10,2.0);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+11,-1.382);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+12,2.382);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+13,-1.618);
ObjectSet(objname,OBJPROP_FIRSTLEVEL+14,2.618);
ObjectSetFiboDescription(objname,0,"Box Edge = %$");
ObjectSetFiboDescription(objname,1,"Initial Stop = %$");
ObjectSetFiboDescription(objname,2,"Box Edge = %$");
ObjectSetFiboDescription(objname,3,"Entry = %$");
ObjectSetFiboDescription(objname,4,"TP2 Stop = %$");
ObjectSetFiboDescription(objname,5,"TP1 and TP3 Stop = %$");
ObjectSetFiboDescription(objname,6,"TP2 = %$");
ObjectSetFiboDescription(objname,7,"Entry = %$");
ObjectSetFiboDescription(objname,8,"TP2 Stop = %$");
ObjectSetFiboDescription(objname,9,"TP1 and TP3 Stop = %$");
ObjectSetFiboDescription(objname,10,"TP2 = %$");
ObjectSetFiboDescription(objname,11,"TP3 = %$");
ObjectSetFiboDescription(objname,12,"TP3 = %$");
ObjectSetFiboDescription(objname,13,"TP4 = %$");
ObjectSetFiboDescription(objname,14,"TP4 = %$");
//dys++; if (dys >= NumDays) break;
}
WindowRedraw();
return(0);
}
//+------------------------------------------------------------------+
void del_obj() {
//+------------------------------------------------------------------+
int k=0;
while (k<ObjectsTotal()) {
string objname = ObjectName(k);
if (StringSubstr(objname,0,3) == "BF-")
ObjectDelete(objname);
else
k++;
}
return(0);
}
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
---