breakout-zones
//+------------------------------------------------------------------+
//|TZ-Breaktout.mq4 |
//|Shimodax |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright Shimodax"
#property link "http://www.strategybuilderfx.com/forums/showthread.php?t=15439"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 LightGray
#property indicator_color4 LightGray
#property indicator_color5 Blue
//----
extern int LocalTimeZone= 2;
extern int DestTimeZone= 6;
extern int PipsForEntry= 5;
//----
double Zone1Upper[];
double Zone2Upper[];
double Zone1Lower[];
double Zone2Lower[];
double SignalsBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Zone1Upper);
SetIndexEmptyValue(0, 0.0);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Zone1Lower);
SetIndexEmptyValue(1, 0.0);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(2,Zone2Upper);
SetIndexEmptyValue(2, 0.0);
SetIndexStyle(3,DRAW_NONE);
SetIndexBuffer(3,Zone2Lower);
SetIndexEmptyValue(3, 0.0);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4, 156);
SetIndexBuffer(4, SignalsBuffer);
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars= IndicatorCounted(),
lastbar, result;
//----
if (Bars<=100)
return(0);
if (counted_bars>0)
counted_bars--;
//----
lastbar= Bars - counted_bars;
//----
BreakoutRanges(0, lastbar, LocalTimeZone, DestTimeZone);
return(0);
}
//+------------------------------------------------------------------+
//| Compute index of first/last bar of yesterday and today |
//+------------------------------------------------------------------+
int BreakoutRanges(int offset, int lastbar, int tzlocal, int tzdest)
{
int i, j, k,
tzdiff= tzlocal - tzdest,
tzdiffsec= tzdiff*3600,
tidxstart= { 0, 0},
tidxend= { 0, 0 };
double thigh= { 0.0, 0.0 },
tlow= { 99999.9, 99999.9 };
string tfrom= { "04:00", "08:00" ,/*rest of day: */ "12:00"},
tto= { "08:00", "12:00", /*rest of day: */ "24:00" },
tday;
bool inperiod= -1;
datetime timet;
// search back for the beginning of the day
tday= TimeToStr(Time-tzdiffsec, TIME_DATE);
for( ;lastbar<Bars; lastbar++)
{
if (TimeToStr(Time - tzdiffsec, TIME_DATE)!=tday)
{
lastbar--;
break;
}
}
// find the high/low for the two periods and carry them forward through the day
tday= "XXX";
for(i= lastbar; i>=offset; i--)
{
timet= Time - tzdiffsec; // time of this bar
//----
string timestr= TimeToStr(timet, TIME_MINUTES), // current time HH:MM
thisday= TimeToStr(timet, TIME_DATE); // current date
// for all three periods (first period, second period, rest of day)
for(j= 0; j<3; j++)
{
if (tfrom<=timestr && timestr<tto)
{ // Bar in this period
if (inperiod!=j)
{ // entered new period, so last one is completed
if (j>0)
{ // now draw high/low back over the recently completed period
for(k= tidxstart; k>=tidxend; k--)
{
if (j-1==0)
{
Zone1Upper= thigh;
Zone1Lower= tlow;
}
if (j-1==1)
{
Zone2Upper= thigh;
Zone2Lower= tlow;
}
}
}
inperiod= j; // remember current period
}
if (inperiod==2) // inperiod==2 (end of day) is just to check completion of zone 2
break;
// for the current period find idxstart, idxend and compute high/low
if (tidxstart==0)
{
tidxstart= i;
tday= thisday;
}
tidxend= i;
//----
thigh= MathMax(thigh, High);
tlow= MathMin(tlow, Low);
}
}
// carry forward the periods for which we have definite high/lows
if (inperiod>=1 && tday==thisday)
{ // first time period completed
Zone1Upper= thigh + PipsForEntry*Point;
Zone1Lower= tlow - PipsForEntry*Point;
//----
if (inperiod>=2)
{ // second period completed
Zone2Upper= thigh + PipsForEntry*Point;
Zone2Lower= tlow - PipsForEntry*Point;
}
}
else
{ // none yet to carry forward (zero to clear old values, e.g. from switching timeframe)
Zone1Upper= 0;
Zone1Lower= 0;
Zone2Upper= 0;
Zone2Lower= 0;
}
// at the beginning of a new day reset everything
if (tday!="XXX" && tday!=thisday)
{
Print("#", i, "new day ", thisday, "/", tday);
//----
tday= "XXX";
//----
inperiod= -1;
//----
for(j= 0; j<2; j++)
{
tidxstart= 0;
tidxend= 0;
thigh= 0;
tlow= 99999;
}
}
}
return(0);
}
//+------------------------------------------------------------------+
路过,学习下 学习了,不错,讲的太有道理了 路过,支持一下啦 我是来刷分的,嘿嘿 找到好贴不容易,我顶你了,谢了 我是个凑数的。。。 谢谢楼主分享 帮你顶下哈!! 学习了,不错
页:
[1]
2