股票量化软件:验证流言--- 全日交易取决于亚洲时段的交易行情
“全日交易取决于亚洲时段的交易行情”。
爱因斯坦认为,一切都是相对的,一旦我们推敲任何陈述细节的话,我们会 马上 相信他说的是对的。 例如,有个问题是关于亚洲市场的交易时间的。 让我们来看一看以下图表,交易时间如下所示。赫兹量化软件
地区
城市
冬季时间
开市
冬季时间
收市
夏季时间
开市
夏季时间
收市
亚洲
东京
香港
新加坡
03:00
04:00
04:00
11:00
12:00
12:00
04:00
05:00
04:00
12:00
13:00
12:00
欧洲
法兰克福
苏黎世
巴黎
伦敦
9:00
9:00
9:00
10:00
17:00
17:00
17:00
18:00
09:00
09:00
09:00
10:00
17:00
17:00
17:00
18:00
美洲
纽约
芝加哥
16:00
17:00
24:00
01:00
16:00
17:00
24:00
01:00
大洋洲
威灵顿
悉尼
00:00
01:00
08:00
09:00
00:00
01:00
08:00
09:00
表 1 外汇交易时段
我们可以发现,亚洲交易时段在冬令时开始于 3:00,结束于 12:00,在夏令时开始于 4:00,结束于 13:00。 但欧洲的交易时间开始于 9.00。 那么问题来了 - 亚洲市场的开放时间到底是 3.00 到 9.00 还是 3.00 到 13.00?赫兹量化软件 另一个问题是关于服务器时间,由于不同经纪人的服务器时间不同,故没有必要与莫斯科时间保持一致,还有一个问题是关于冬令时/夏令时的时间调整 - 部分经纪人并不做此调整。 因此,我们需要将此纳入我们的研究范围内。 “..全日交易取决于此”是什么意思? 如果亚洲时段行情上涨,价格是否会持续涨至下一个时段?赫兹量化软件
首先,让我们来看看图 1。 该时段已用 Igor Kim 开发的指标 “i-Sessions” 涂上了不同颜色。 从 3.00 到 13.00 的时段填充为黑色(“亚洲”)。 欧洲时段(9.00 至 18.00)涂上了较浅颜色,美洲时段(16.00 至 24.00)则为最浅颜色。赫兹量化软件
图 1 NZDUSD 交易时段图
我将进一步详细描述,以帮助新手了解透彻。
因此,我的 Expert Advisor “1-Session” 设计用于解决以下问题:
必须计算时段开盘和收盘的价位,而时段由我们指定。 让我们假设如果时段的开盘价位高于收盘价位,则该时段为下跌行情,反之则为上涨行情。赫兹量化软件
如果开盘价位等于收盘价位,则行情中性。赫兹量化软件
我试着对所有的 Expert Advisor 代码进行注释,以令新手(包括我在内)易于理解。
//+------------------------------------------------------------------+ //| 1-Session.mq4 | //| Copyright © 2009, Igor Alexandrov | //| sydiya@rambler.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Igor Alexandrov" #property link "sydiya@rambler.ru" //---- Input parameters extern string Open_session = "01:00"; //Opening time of the session to study extern string Close_session = "10:00"; //Closing time of the session to study extern int Day_kol_vo = 50; //Number of days to study extern int Hour_kol_vo = 15; //Number of hours to study after the session extern int Profit = 20; //Take Profit value to verify //---------------------------------------------------------------------------- string Symb; //Trade symbol of the expert attached //----------------------------Starting---------------------------------------- int start() { //the main bracket begins int Shift_open_H1, //Number of hourly bar with the same opening time as daily bar Shift_open_bars_session, //Number of hourly bar, that opens the session Shift_close_bars_session, //Number of hourly bar, that closes the session STOP_LEVER=0; //Minimal distance for TP and SL double Open_bars_session, //Opening price of the first bar of the session Close_bars_session, //Closing price of the last bar of the session Vira_session, //Maximal price of the session Total_TP=0, //Counter of Take Profit executions Total_SL=0, //Counter of Stop Loss executions Total_day=0, //Number of days to study Total_SL_TP=0, //Counter of neutral sessions Maina_session; //Minimal price of the session datetime Time_open_day, //Opening time of the i-th daily bar Time_open_session, //Opening time of the session (datetime format) Time_close_session; //Closing time of the session (datetime format) string String_open_H1; //Opening time of the first hourly bar of the day to study //as string format "yyyy.mm.dd" bool Session_buy=false, //Bullish session flag Session_sell=false; //Bearish session flag Symb=Symbol(); //Symbol name //Minimal distance for TP and SL STOP_LEVER=MarketInfo(Symb,MODE_STOPLEVEL); // daily bars cycle for(int i=Day_kol_vo;i>0;i --) { //bracket for daily bars cycle //Counter for days studied Total_day++; //opening time of the i-th daily bar Time_open_day=iTime(Symb,PERIOD_D1,i); //number of hourly bar with the same opening time as daily bar Shift_open_H1=iBarShift(Symb,PERIOD_H1,Time_open_day,false); //convert opening time of the first hourly bar to the string like "yyyy.mm.dd" String_open_H1=TimeToStr(Time_open_day,TIME_DATE); //opening time for the session to study (in the datetime format) Time_open_session=StrToTime(String_open_H1+" "+Open_session); //number of hourly bar from which session begins Shift_open_bars_session=iBarShift(Symb,PERIOD_H1,Time_open_session,false); //closing time of the session to study (in datetime format) Time_close_session=StrToTime(String_open_H1+" "+Close_session); //number of last hourly bar of the session Shift_close_bars_session=iBarShift(Symb,PERIOD_H1,Time_close_session,false); //opening price of the first bar of the session Open_bars_session=iOpen(Symb,PERIOD_H1,Shift_open_bars_session); //closing price of the last bar of the session Close_bars_session=iClose(Symb,PERIOD_H1,Shift_close_bars_session); //finding the maximal price of the session Vira_session=iHigh(Symb,PERIOD_H1,iHighest(Symb,PERIOD_H1,MODE_HIGH, (Shift_open_bars_session-Shift_close_bars_session),Shift_close_bars_session)); //finding the minimal price of the session Maina_session=iLow(Symb,PERIOD_H1,iLowest(Symb,PERIOD_H1,MODE_LOW, (Shift_open_bars_session-Shift_close_bars_session),Shift_close_bars_session)); // the opening price is greater than closing price, session is Bearish if(Open_bars_session>Close_bars_session) { Session_buy=false; Session_sell=true; } //The opening price is lower than closing price, session is bullish if(Open_bars_session<Close_bars_session) { Session_buy=true; Session_sell=false; } //The opening price is equal to closing price, session is Neutral if(Open_bars_session==Close_bars_session) { Session_buy=false; Session_sell=false; } // hours counter for checking int PEREBOR=0; //Cycle for hourly bars in the i-th day for(int j=Shift_close_bars_session;j>Shift_close_bars_session-Hour_kol_vo;j --) {//Opening bracket for the hourly bars cycle //hours counter (for checking) PEREBOR++; //if session is bullish if(Session_buy==true && Session_sell==false) { //if maximal price of the hourly bar //is greater than (closing price of the session+Profit+Minimal distance) if(iHigh(Symb,PERIOD_H1,j-PEREBOR)>(Close_bars_session+(Profit+STOP_LEVER)*Point)) { Total_TP++; //Take Profit executed break; //break the cycle(hourly bars) } //if minimal price of the hourly bar //is lower than minimal price of the session if(iLow(Symb,PERIOD_H1,j-PEREBOR)<Maina_session) { Total_SL++; //Stop Loss executed break; //break the cycle(hourly bars) } } //if session is bearish if(Session_buy==false && Session_sell==true) { //if maximal price of the hourly bar //is greater than maximal price of the session if(iHigh(Symb,PERIOD_H1,j-PEREBOR)>Vira_session) { Total_SL++; //Stop Loss executed break; //break the cycle(hourly bars) } //if minimal price of the hourly bar //is lower than (closing price of the session-(Profit + Minimal distance)) if(iLow(Symb,PERIOD_H1,j-PEREBOR)<(Close_bars_session-(Profit+STOP_LEVER)*Point)) { Total_TP++; //Take Profit executed break; //break the cycle(hourly bars) } } //if session is neutral if(Session_buy==false && Session_sell==false) { Total_SL_TP++; //Increase the counter break; //break the cycle(hourly bars) } } // closing bracket for the hourly bars cycle double Pro_Total_TP=(Total_TP/Total_day)*100, //Probabiility of TP execution Pro_Total_SL=(Total_SL/Total_day)*100, //Probability of SL execution Pro_Total_SL_TP=(Total_SL_TP/Total_day)*100; //Probability of neutral sessions int Total_no=Total_day-Total_SL-Total_TP-Total_SL_TP; //TP and SL hasn't executed double Pro_Total_no =(Total_no/Total_day)*100; //Probability that TP and SL will not executed Comment("Checked ",Total_day," days","\n", "Session Opening time ",Open_session," Session Closing time ", Close_session," Number of hours to check after the session ",Hour_kol_vo," Profit ",Profit,"\n", "Take profit has executed ",Total_TP," times","\n", "Stop Loss has executed ",Total_SL," times","\n", "The neutral sessions was ",Total_SL_TP," times","\n", "Neither SL/TP executed ",Total_no," times","\n", "Probability for Take Profit execution ",Pro_Total_TP," %","\n", "Probability for Stop Loss execution ",Pro_Total_SL," %","\n", "Probability for neutral sessions ",Pro_Total_SL_TP," %","\n", "Probability that SL and TP will not executed ",Pro_Total_no," %"); } //Closing bracket for the daily bars return(0); } //-the main bracket ends