818期货学习网 > 外汇知识 > 顺势而为:外汇交易中的道氏理论 >
2014-10-04 17:10 来源:818期货学习网
下面是汉斯123交易系统的指标源码,也是用于Metatrader4.0的交易平台,这是一个全球广泛使用的交易平台,关于该平台的使用方法可以参看《5分钟动量交易系统》或者是《外汇交易进阶》等书,也可以登录这个软件的官方网站免费下载使用手册。
//+ +
//| Hans Breakout.mq4 |
//| Copyright 2009 Dina |
//+ +
#property copyright"520fx.com"
#property link "http: //www.520fx.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_colorl Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
extern int Breakout_Pips=5;
extern int Exit_Hour=23;
extern int From_Hour_1=6;
extern int From_Minute_1=0;
extern int To_Hour_1=9;
extern int TO_Minute_1=59;
extern int From_Hour_2=10;
extern int From_Minute_2=0;
extern int To_Hour_2=13;
extern int TO_Minute_2=59;
extern int Bars_Count=10000;
{
IndicatorBuffers(4);
SetlndexArrow(0,159);
SetlndexStyle(0,DRAW_ARROW,STYLE_SOUD,1,Red);
SetlndexDrawBegin (0,-1);
SetlndexBuffer (0,vl);
SetlndexLabel (0,"High1");
SetlndexArrow (1,159);
SetlndexStyle (l,DRAW_ARROW,STYLE_SOUD,1,Blue);
SetlndexDrawBegin(1,-1);
SetlndexBuffer(1,v2);
SetlndexLabel(1,"Low1");
SetlndexArrow (2,159);
SetlndexStyle (2,DRAW_ARROW,STYLE_SOLID,1,Red);
SetlndexDrawBegin (2,-1);
SetlndexBuffer (2,v3);
SetlndexLabel (2,"High2");
SetlndexArrow (3,159);
SetlndexStyle (3,DRAW_ARROW,STYLE_SOLID,1,Blue);
SetlndexDrawBegin (3,-1);
SetlndexBuffer (3,v4);
SetlndexLabel (3,"Low2");
watermark();
return (0);
}
int start()
{
int i;
int shift;
double price;
datetime calculated 1, calculated2;
double pipsBreakout=Breakout_Pips*Point;
i=Bars_Count;
while(i>=0)
{
// High/Low 1
datetime today=StripTime(Time[i]);
int nowMins=TimeHour(Time[i])*60+TimeMinute(Time[i]);
if(calculated 1
{
calculated 1=today;
double highest1 =High[GetHighest(Symbol(),Period(),M0DE_HIGH,Time[i],From_Hour_l,From_Minute_1,To_Hour_l,To_Minute_l)];
double lowest1=Low[GetLowest(Symbol(),Period(),MODE_LOW,Time[i],From_Hour_l,From_Minute_l,To_Hour_l,To_Minute_1)];
}
if(calculated 1==today &&nowMins < Exit_Hour*60)
{
v1[i]=highest1+pipsBreakout;
v2[i]=lowestl-pipsBreakout;
}
//High/Low 2
if(calculated2==today && nowMins > (To_Hour_2*60) + To_Minute_2)
{
calculated2=today;
double highest2=High [GetHighest(Symbol(),Period(),MODE_HIGH,Time[i],From_Hour_2,From_Minute_2,To_Hour_2,To_Minute_2)];
double lowest2=Low[GetLowest(Symbol(),Period(),MODE_LOW,Time[i],From_Hour_2,From_Minute_2,To_Hour_2,To_Minute_2)];
}
if(calculated2==today && nowMins < Exit_Hour*60)
{
v3[i]=highest2+pipsBreakout;
v4[i]=lowest2-pipsBreakout;
}
i--;
}
return(0);
}
//+ +
datetime StripTime(datetime dt)
{
return(dt-(TimeHour(dt)*3600)-(TimeMinute(dt)*60)-TimeSeconds(dt));
}
//+ +
// | Get highest/lowest bar between a time period.
//+ +
int GetHighest (string symbol,int timeframe,int price_mode,datetime date, int from_hour,int from_minute,int to_hour,int to_minute)
{
date=StripTime(date);
datetime from_time=date+(from_hour*3600)+(from_minute*60);
datetime to_time=date+(to_hour*3600)+(to_minute*60);
int from_bar = iBarShift(symbol,timeframe,from_time,false);
int to_bar=iBarShift(symbol,timeframe,to_time,false);
int hh=Highest(symbol,timeframe,price_mode,from_bar — to_bar+1,to_bar);
return(hh);
}
int GetLowest (string symbol,int timeframe,int price_mode,datetime date,int from_hour,int from_minute,int to_hour,int to_minute)
{
date = StripTime (date);datetime from_time = date + (from_hour*3600)+(from一minute*60);
datetime to_time = date+(to_hour*3600)+(to_minute*60);
int from_bar = iBarShift(symbol,timeframe,from_time,false);
int to_bar = iBarShift(symbol,timeframe,to_time,false);
int 11= Lowest(symbol,timeframe,price_mode,from_bar—to_bar+1,to_bar);
return(11);
}
void watermark ()
{
ObjectCreate("Dina",OBJ_LABEL,0,0,0);
ObjectSetText("Dina","www.520fx.com",15,"Times New Roman",Yellow);
ObjectSet("Dina",OBJPROP_CORNER,2);
ObjectSet("Dina",OBJPROP_XDISTANCE,5);
ObjectSet("Dina",OBJPROP_YDISTANCE,10);
return (0)。
汉斯方法练级的基础就是跟随主力的作息规律,明白这一点非常重要,主力与单边走势相关,散户与震荡走势相关,日内的震荡区间往往表明行情处于散户阶段,BIG MAN还没有入场,一旦形成区间突破往往意味着主力开始行动,而外汇市场上的主力活动具有明显的作息规律,一是欧洲市场,二是美国早盘,明白这两点就不难明白汉斯方法有效的原因了。同时,大家发现汉斯这类日内交易法与趋势跟踪交易法的区别了吗?这类日内交易法基本上不会加仓,而且惯于采用时间出场法,这我们在学习本课内容时需要注意的一点。
© Copyright 2014 818期货学习网 All Rights Reserved. 浙ICP备14000419号-1