第二节 汉斯方法的基础

第二节 汉斯方法的基础

汉斯方法基本上是建立在本课第一节我们介绍的时间规律第一条的基础上,这种方法与英镑择时交易法类似,目的是跟随日内主力交易者的行动方向,但是随着采用这种方法的人数的增加,这种方法可能需要一些参数改变才能保持效率。国际上著名的趋势突破系统汉斯策略引起了广泛的关注,已经发展更新了多种版本,当初也引起了国人的关注,但草草研究的结果认为程序跑不通或者亏损就把它盖棺定论“枪毙”了。但是,国外仍然持续研究发展它,版本从V1.0到V9.0,测试报告也从几个月到几年,甚至有从1999年至今的测试报告。

汉斯交易系统专门用于欧元兑美元以及英镑兑美元的日内交易,每个货币基本上有两次交易,分别处于两个时区波幅突破之后。具体的汉斯交易系统规则如下:

(1)进场规则。

每日17:00,找到英镑兑美元和欧元兑美元今日13:00~17:00的最高价和最低价,下单Buy Stop和Sell Stop;每日21:00,找到英镑兑美兀和欧元兑美元今日17:00~21:00的最高价和最低价,下单Buy Stop和Sell Stop。其中Buy Stop =最高价+5点,Sell Stop=最低价-5点。

(2)出场规则。

EUR/USD的出场:止盈=Buy Stop+80,止损=Buy Stop-50;止盈=Sell Stop-80;止损=Sell Stop+50;有30点浮动利润时将止损移至开仓价位。

GBP/USD的出场:止盈=Buy Stop+120;止损=Buy Stop-70;止盈=Sell Stop-120,止损=Sell Stop+70;有40点浮动利润时将止损移至开仓价位。

(3)辅助规则。

每日早7:00,平掉手上所有单子;如果交易者已经在某个方向上建立起了相应的头寸,并处于持仓过程中,但汇价却突破了另外一边,这时候你就应该平仓并反向建仓。当你最初持仓的止损处于区间内,则汇价会先触及止损再突破另外一边;当你最初持仓的止损处于区间之外,则汇价会先触及另外一边,这时候就不用等到止损触及了,应该在触及另外一边的时候就平掉最初的仓位并建立起相反的头寸。

汉斯策略最初是由Hans Van Der Helm开发出来的,现在得到了欧美外汇界的高度关注,并不断有新的版本公布,其绩效不断上升,我们这里将其中一个版本的MQL源码给出,你可以自行研究,我们的下载网站也会提供某些版本的汉斯指标和智能交易系统供你使用。

下面第一个源码是汉斯智能交易系统(EA)檣标系统,第二个源码是汉斯指标系统,指标系统需要肉眼观察和判断,智能交易系统则可以自动交易,不过后者不能完全遵照系统最初设计的原意。

//+ +

//|Hansl23MV22|

//| Copyright ? 2009, Dina|

//|

//+ +

#property copyright“Copyright ? 2009,Dina”


//Normalize times

if (EOD==24) EOD=0;

if (FridayClosing==0) FridayClosing=24;

//Setup comment

string Text=“Hans123”+ Symbol();

//Setup orders

if(Hour()==Startl && Minute ()<10){

MN=1;

SetOrders(Text,MN);

}

if(Hour()==Start2 && Minute()<10 && FirstSessionOnly==0){

MN=2;

SetOrders(Text,MN);

}

if(Hour()==Start2 && Minute()<10 && FirstSessionOnly==0){

MN==2;

SetOrders(Text,MN);

}

//Manage opened orders

for(i=0;i<OrdersTotal();i++){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==Text){

//close open positions at EOD

if(Hour()==EOD||(DayOfWeek()>=5 && Hour() ==FridayClosing-1 && Minute() >=50)){

switch(OrderType()){

case OP_BUY:OrderClose (OrderTicket(),OrderLots(),Bid,3,Red);

break;

case OP_BUY:OrderClose (OrderTicket(),OrderLots(),Bid,3,Red);

case OP_SELL:OrderClose (OrderTicket(),OrderLots(),Ask,3,Red);

break;

default:OrderDelete (OrderTicket());

break;

}

Sleep (10000);

}

else{

//move at BE if profit>BE

if (TrailingStop==0){

if (OrderType()==OP_BUY){

if (High[0]-OrderOpenPrice()>=BreakEven*Point && OrderStopLoss()<OrderOpenPrice()){

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTake Profit(),0,Green);

Sleep (10000);

}

}

if (OrderType()==OP_SELL){

if (OrderOpenPrice()-Low[0]>=BreakEven*Point && OrderStopLoss()>OrderOpenPrice()){

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);

Sleep (10000);

}

}

}

//use trailing stop else

else{

if (OrderType()==OP一BUY){

if (High[0]-OrderStopLoss()>TrailingStop*Point){

OrderModify (OrderTicket(),OrderOpenPrice(),High[0]-TrailingStop*Point,OrderTakeProfit (),0,Green);

Sleep(10000);

}

}

if (OrderType()==OP_SELL){

if(OrderStopLoss()-Low[0]>TrailingStop*Point){

OrderModify(OrderTicket(),OrderOpenPrice(),Low[0]+ TrailingStop*Point,OrderTakeProfit (),0,Green);

Sleep (10000);

}

}

}

}

}

}

return (0);

}

//+ +

void SetOrders (string Text,int MN){

int i,Ticket,Bought,Sold;

double EntryLong,EntryShort,SLLong,SLShort,TPLong,TPShort;

//Determine range

Entry Long

=iHigh(NULL,60,Highest(NULL,60,MODE_HIGH,Length,1))+(Pips/*+Marketlnfo(Symbol(),MODE_SPREAD)*/)*Point;

EntryShort=iLow(NULL,60,Lowest(NULL,60,MODE_LOW,Length,1))-Pips*Point;

SLLong=MathMax(EntryLong-StopLoss*Point,EntryShort);

SLShort=MathMin(EntryShort+StopLoss*Point,Entry Long);

TPLong=EntryLong+TakeProfit*Point;

TPShort=EntryShort-TakeProfit*Point;

//Send orders

for (i=0;i<OrdersTotal();i++){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==Text && OrderMagicNumber()==MN){

if(OrderType()==0P_BUYSTOP||OrderType()==OP_BUY)Bought++;

if(OrderType()==OP_SELLSTOP||OrderType()==OP_SELL)Sold++;

}

}

if(Bought==0){//no buy order

Ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,EntryLong,3,SLLong,TPLong,Text,MN,0,Blue);

if(Ticket<0 high="" 0="">=EntryLong)

Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,SLLong,TPLong,Text,MN,0,Blue);

Sleep (10000);

}

if(Sold==0){ //no sell order

Ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,EntryShort,3,SLShort,TPShort,Text,MN,0,Magenta);

if(Ticket<0 && Low[0]<=EntryShort)

Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,SLShort,TPShort,Text,MN,0,Magenta);

Sleep (10000);

}

//Check orders

for(i=0;i<OrdersTotal();i++){

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if(OrderComment()==Text && OrderMagicNumber()==MN) {

if(OrderType()==OP_BUYSTOP &&(MathAbs(OrderOpenPrice()-EntryLong)>Point

||      MathAbs(OrderStopLoss()-TPLong) >Point    ||

MathAbs(OrderTakeProfit()-TPLong)>Point))

 OrderModify(OrderTicket(),EntryLong,SLLong,TPLong,0,Blue);

if(OrderType()==OP_SELLSTOP && (MathAbs(OrderOpenPrice()-EntryShort) >Point

||    MathAbs (OrderStopLoss()-SLShort)>Point  ||

MathAbs(OrderTakeProfit()-TPShort) >Point))

 OrderModify(OrderTicket(),EntryShort,SLShort,TPShort,0,Magenta);

下面是汉斯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还没有入场,一旦形成区间突破往往意味着主力开始行动,而外汇市场上的主力活动具有明显的作息规律,一是欧洲市场,二是美国早盘,明白这两点就不难明白汉斯方法有效的原因了。同时,大家发现汉斯这类日内交易法与趋势跟踪交易法的区别了吗?这类日内交易法基本上不会加仓,而且惯于采用时间出场法,这我们在学习本课内容时需要注意的一点。