下载MetaTrader 5
要添加评论,请登录注册
如何选择最合适的信号并立刻订阅
龙飞
86
龙飞 2007.05.23 07:38 
龙飞
86
龙飞 2007.05.23 07:39  

//+------------------------------------------------------------------+
//| _4TF HAS BarZH15_3ZB. mq4 |
//| Modified by Matsu, from #MTF Supertrend Bar.mq4 |
//| Copyright ?2006, Eli hayun |
//| http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, Eli hayun"
#property link "http://www.elihayun.com"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 9
#property indicator_buffers 32

#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Blue
#property indicator_color7 Red
#property indicator_color8 Blue
#property indicator_color9 Red
#property indicator_color10 Blue
#property indicator_color11 Red
#property indicator_color12 Blue
#property indicator_color13 Red
#property indicator_color14 Blue
#property indicator_color15 Red
#property indicator_color16 Blue

//---- parameters
extern int MaMetod = 2;
extern int MaPeriod = 6;
extern int MaMetod2 = 3;
extern int MaPeriod2 = 2;
extern int BarWidth = 0;
extern color BarColorUp = Blue;
extern color BarColorDown = Red;
extern color TextColor = White;
extern int MaxBars=500;

double Gap = 1; // Gap between the lines of bars
//---- buffers
double buf4_up[500];
double buf4_down[500];
double buf3_up[500];
double buf3_down[500];
double buf2_up[500];
double buf2_down[500];
double buf1_up[500];
double buf1_down[500];
double haOpen;
double haClose;

//------------

double buf8_up[];
double buf8_down[];
double buf7_up[];
double buf7_down[];
double buf6_up[];
double buf6_down[];
double buf5_up[];
double buf5_down[];

double buf12_up[];
double buf12_down[];
double buf11_up[];
double buf11_down[];
double buf10_up[];
double buf10_down[];
double buf9_up[];
double buf9_down[];

string shortname = "";
bool firstTime = true;

int ArrSize = 110;//159;
int UniqueNum = 228;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
if(Period()!=15)
{
return;
}

//SetAutoDisplay();
firstTime = true;

SetIndexStyle(0,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(0,ArrSize);
SetIndexBuffer(0,buf8_up);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(1,ArrSize);
SetIndexBuffer(1,buf8_down);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(2,ArrSize);
SetIndexBuffer(2,buf7_up);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(3,ArrSize);
SetIndexBuffer(3,buf7_down);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(4,ArrSize);
SetIndexBuffer(4,buf6_up);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(5,ArrSize);
SetIndexBuffer(5,buf6_down);
SetIndexEmptyValue(5,0.0);
SetIndexStyle(6,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(6,ArrSize);
SetIndexBuffer(6,buf5_up);
SetIndexEmptyValue(6,0.0);
SetIndexStyle(7,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(7,ArrSize);
SetIndexBuffer(7,buf5_down);
SetIndexEmptyValue(7,0.0);

SetIndexStyle(8,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(8,ArrSize);
SetIndexBuffer(8,buf4_up);
SetIndexEmptyValue(8,0.0);
SetIndexStyle(9,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(9,ArrSize);
SetIndexBuffer(9,buf4_down);
SetIndexEmptyValue(9,0.0);
SetIndexStyle(10,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(10,ArrSize);
SetIndexBuffer(10,buf3_up);
SetIndexEmptyValue(10,0.0);
SetIndexStyle(11,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(11,ArrSize);
SetIndexBuffer(11,buf3_down);
SetIndexEmptyValue(11,0.0);
SetIndexStyle(12,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(12,ArrSize);
SetIndexBuffer(12,buf2_up);
SetIndexEmptyValue(12,0.0);
SetIndexStyle(13,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(13,ArrSize);
SetIndexBuffer(13,buf2_down);
SetIndexEmptyValue(13,0.0);
SetIndexStyle(14,DRAW_ARROW,0,BarWidth,BarColorDown);
SetIndexArrow(14,ArrSize);
SetIndexBuffer(14,buf1_up);
SetIndexEmptyValue(14,0.0);
SetIndexStyle(15,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(15,ArrSize);
SetIndexBuffer(15,buf1_down);
SetIndexEmptyValue(15,0.0);


SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
SetIndexLabel(4,NULL);
SetIndexLabel(5,NULL);
SetIndexLabel(6,NULL);
SetIndexLabel(7,NULL);

SetIndexLabel(8,NULL);
SetIndexLabel(9,NULL);
SetIndexLabel(10,NULL);
SetIndexLabel(11,NULL);
SetIndexLabel(12,NULL);
SetIndexLabel(13,NULL);
SetIndexLabel(14,NULL);
SetIndexLabel(15,NULL);

IndicatorDigits(0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
firstTime = true;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i=0, y15m=0, y2h=0, y1h=0, y30m=0,y4h=0, y8h=0, y16h=0, y32h=0, yy;
int limit=Bars-counted_bars;

int Period_1, Period_2, Period_3, Period_4,Period_5, Period_6, Period_7, Period_8;
switch(Period())
{
case 1:
Period_1=1; Period_2=5; Period_3=15; Period_4=30;
break;
case 5:
Period_1=5; Period_2=15; Period_3=30; Period_4=60;
break;
case 15:
Period_1=15; Period_2=30; Period_3=60; Period_4=120;
Period_5=240; Period_6=480; Period_7=960; Period_8=1920;
break;
}


shortname = "MTF HAS ("+Period_1+","+Period_2+", "+Period_3+", "+Period_4+", "+Period_5+","+Period_6+", "+Period_7+", "+Period_8+")";
IndicatorShortName(shortname);

datetime TimeArray_32H[], TimeArray_16H[], TimeArray_8H[], TimeArray_4H[],TimeArray_2H[], TimeArray_1H[], TimeArray_30M[], TimeArray_15M[];
//----

if (firstTime || NewBar())
{
firstTime = false;
int win = UniqueNum; // WindowFind(shortname);
double dif = Time[0] - Time[1];
for (int ii=ObjectsTotal()-1; ii>-1; ii--)
{
if (StringFind(ObjectName(ii),"FF_"+win+"_") >= 0)
ObjectDelete(ObjectName(ii));
else
ii=-1;
}

double shift = 0.2;
for (ii=0; ii<8; ii++)
{
string txt = "??";
double gp;
switch (ii)
{
case 0: txt = tf2txt(Period_1); gp = 1 + shift;
break;
case 1: txt = tf2txt(Period_2); gp = 1 + Gap + shift;
break;
case 2: txt = tf2txt(Period_3); gp = 1 + Gap*2 + shift;
break;
case 3: txt = tf2txt(Period_4); gp = 1 + Gap*3 + shift;
break;
case 4: txt = tf2txt(Period_5); gp = 1 + Gap*4 + shift;
break;
case 5: txt = tf2txt(Period_6); gp = 1 + Gap*5 + shift;
break;
case 6: txt = tf2txt(Period_7); gp = 1 + Gap*6 + shift;
break;
case 7: txt = tf2txt(Period_8); gp = 1 + Gap*7 + shift;
break;
}
string name = "FF_"+win+"_"+ii+"_"+txt;
ObjectCreate(name, OBJ_TEXT, WindowFind(shortname),
iTime(NULL,0,0)+dif*3, gp);
ObjectSetText(name, txt,8,"Arial", TextColor);
}
}

ArrayCopySeries(TimeArray_32H,MODE_TIME,Symbol(),Period_8);
ArrayCopySeries(TimeArray_16H,MODE_TIME,Symbol(),Period_7);
ArrayCopySeries(TimeArray_8H,MODE_TIME,Symbol(),Period_6);
ArrayCopySeries(TimeArray_4H,MODE_TIME,Symbol(),Period_5);

ArrayCopySeries(TimeArray_2H,MODE_TIME,Symbol(),Period_4);
ArrayCopySeries(TimeArray_1H,MODE_TIME,Symbol(),Period_3);
ArrayCopySeries(TimeArray_30M,MODE_TIME,Symbol(),Period_2);
ArrayCopySeries(TimeArray_15M,MODE_TIME,Symbol(),Period_1);

for(i=0, y15m=0, y2h=0, y1h=0, y30m=0,y4h=0, y8h=0, y16h=0, y32h=0;i<MaxBars;i++)
{
if (Time[i]<TimeArray_32H[y15m]) y32h++;
if (Time[i]<TimeArray_16H[y2h]) y16h++;
if (Time[i]<TimeArray_8H[y1h]) y8h++;
if (Time[i]<TimeArray_4H[y30m]) y4h++;

if (Time[i]<TimeArray_15M[y15m]) y15m++;
if (Time[i]<TimeArray_2H[y2h]) y2h++;
if (Time[i]<TimeArray_1H[y1h]) y1h++;
if (Time[i]<TimeArray_30M[y30m]) y30m++;

for (int tf = 0; tf < 8; tf++)
{
int prd;
switch (tf)
{
case 0: prd = Period_1; yy = y15m; break;
case 1: prd = Period_2; yy = y30m; break;
case 2: prd = Period_3; yy = y1h; break;
case 3: prd = Period_4; yy = y2h; break;

case 4: prd = Period_5; yy = y4h; break;
case 5: prd = Period_6; yy = y8h; break;
case 6: prd = Period_7; yy = y16h; break;
case 7: prd = Period_8; yy = y32h; break;
}


haOpen = iCustom(NULL,prd,"Heiken_Ashi_Smoothed", MaMetod, MaPeriod, MaMetod2,MaPeriod2,2,yy) ;
haClose = iCustom(NULL,prd,"Heiken_Ashi_Smoothed", MaMetod, MaPeriod, MaMetod2,MaPeriod2,3,yy) ;

double dUp = EMPTY_VALUE; // iCustom(NULL, prd, "SuperTrend", false, 1, yy);
double dDn = EMPTY_VALUE; //iCustom(NULL, prd, "SuperTrend", false, 0, yy);

if (haOpen<haClose) dDn = 1; else dUp = 1;

switch (tf)
{
case 0:
if (dUp == EMPTY_VALUE)
{
buf1_down[i] = 1;
//Print("buf1_down[" + i +"]" + buf1_down[i]);
}
else
{
buf1_up[i] = 1;
//Print("buf1_up[" + i +"]" + buf1_up[i]);
}
break;
case 1: if (dUp == EMPTY_VALUE) buf2_down[i] = 1 + Gap *
1; else buf2_up[i] = 1 + Gap * 1; break;
case 2: if (dUp == EMPTY_VALUE) buf3_down[i] = 1 + Gap *
2; else buf3_up[i] = 1 + Gap * 2; break;

case 3:
if (dUp == EMPTY_VALUE)
{
buf4_down[i] = 1 + Gap * 3;
//Print("buf4_down[" + i +"]" + buf4_down[i]);
}
else
{
buf4_up[i] = 1 + Gap * 3;
//Print("buf4_up[" + i +"]" + buf4_up[i]);
}

case 4:
if (dUp == EMPTY_VALUE)
{
buf5_down[i] = 1 + Gap * 4;
//Print("buf5_down[" + i +"]" + buf5_down[i]);
}
else
{
buf5_up[i] = 1 + Gap * 4;
//Print("buf5_up[" + i +"]" + buf5_up[i]);
}
break;
case 5: if (dUp == EMPTY_VALUE) buf6_down[i] = 1 + Gap *
5; else buf6_up[i] = 1 + Gap * 5; break;
case 6:
if (dUp == EMPTY_VALUE)
{
buf7_down[i] = 1 + Gap * 6;
//Print("buf7_down[" + i +"]" + buf7_down[i]);
}
else
{
buf7_up[i] = 1 + Gap * 6;
////Print("buf7_up[" + i +"]" + buf7_up[i]);
}
break;
case 7: if (dUp == EMPTY_VALUE) buf8_down[i] = 1 + Gap *
7; else buf8_up[i] = 1 + Gap * 7; break;
}
}
}

return(0);
}
//+------------------------------------------------------------------+

string tf2txt(int tf)
{
if (tf == PERIOD_M1) return("M1");
if (tf == PERIOD_M5) return("M5");
if (tf == PERIOD_M15) return("M15");
if (tf == PERIOD_M30) return("M30");
if (tf == PERIOD_H1) return("H1");
if (tf == 120) return("H2");
if (tf == PERIOD_H4) return("H4");
if (tf == 480) return("H8");
if (tf == 960) return("H16");
if (tf == 1920) return("H32");
if (tf == 3840) return("H64");
if (tf == 7680) return("H128");
if (tf == PERIOD_D1) return("D1");
if (tf == PERIOD_W1) return("W1");
if (tf == PERIOD_MN1) return("MN1");

return("??");
}
bool NewBar()
{
static datetime dt = 0;

if (Time[0] != dt)
{
dt = Time[0];
return(true);
}
return(false);
}

okwh
1630
okwh 2007.05.24 08:37  
因为MT限制一个指标文件最多8个指标buffer,
看你使用的arrow, 可把其它该用Object来绘制显示.
/
要添加评论,请登录注册