818期货学习网 > 外汇知识 > 外汇短线交易的24堂精品课 >
2014-08-09 20:54 来源:818期货学习网
下面是汉斯123交易系统的指标源码,也是用于Metatrader4.0的交易平台,这是一个全球广泛使用的交易平台,关于该平台的使用方法可以参看《5分钟动量交易系统》或者是《外汇交易进阶》等书,也可以登录我们的网站下载使用手册。
//+---------------------------------------------+
//| Hans Breakout.mq4 |
//| Copyright 2009 Dina |
//+---------------------------------------------+
#property copyright “520fx.com”
#property link “ttp://www.52Ofx.com”
#property indicator_chart_window
#property indicator_buffers4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
extern int Breakout_Pips=5;
extem1 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;
exlern mt From_Hour_2=10;
extern int From_Minute_2=0;
extern inl To_Hour_2=13;
extern inl To_Minule_2=59;
extern int Bars_Count=10000;
//----buffers
double v1 [];
double v2 [];
double v3 [];
double v4 [];
int init()
{
IndicalorBuffers(4);
SetIndexAnuw(0,159);
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1,Red);
SetIndexDrawBegin(0,-1);
SetIndexBuffer(0,v1);
SetlndexLabel(0,“High1”);
SetlndexArrow(1,159);
SetlndexStyle(1,DRAW_ARROW,STYLE_SOUD,1,Blue);
SetlndexDrawBegin(1,-1);
SetIndexBuffer(1,v2);
SetIndexLabel(1,“Low1”);
SetlndexArrow(2,159);
SetlndexStyle(2,DRAW_ARROW,STYLE_SOUD,1,Red);
SetlndexDrawBegin(2,-1);
SetlndexBuffer(2,v3);
SetlndexLabel(2,“High2”);
SetlndexArrow(3,159);
SetIndexStyle(3,DRAW_ARROW,STYLE_SOUD,1,Blue);
SetlndexDrawBegin(3,-1);
SetlndexBuffer(3,v4);
SetlndexLabel(3,“Low2”);
watennark();
return(0);
}
int start()
{
int i;
int shift;
double price;
datetime calculated1,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(calculatedl
{
calculated 1=today;
double highest1=High[GetHighest(Symbol(),Period(),MODE_HIGH,Time[i],From_Hour_1,From_Minute_1,To_Hour_1,To_Minute_1)];
double lowest1=Low[GetLowest(Symbol(),Period(),MODE_LOW,Time[i],From_Hour_1,From_Minute_1,To_Hour_1,To_Minute_1)];
}
if(calculated1==today && nowMins<Exit_Hour*60)
{
v1[i]=highest1+pipsBreakout;
v2[i]=lowest1-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--;
}
retum(0);
}
//+---------------------------------------------+
datetime StripTime(datetime dt)
{
retum(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 ll=Lowest(symbol,timeframe,price_mode,from_bar-to_bar+1,to_bar);
retum(ll);
}
void watermark()
ObjectCreate(“Dina”,OBJ_LABEL,0,0,0);
ObjectSetText(“Dina”,“www.52Ofx.com”,15,“Times New Roman”,Yellow);
ObjectSet(“Dina”,OBJPROP_CORNER,2);
ObjectSet(“Dina”,OBJPRO_XDISTANCE,5);
ObjectSet(“Dina”,OBJPROP_YDISTANCE,10);
retum(0);
© Copyright 2014 818期货学习网 All Rights Reserved. 浙ICP备14000419号-1