交易逻辑:
风险/回报比例:
等待新闻即将发布的时间:
if(Date>(TimeCurrent()-(xTime*60)))
等待订单关闭的时间:
基本面交易者EA支持的国家:
基本面交易者EA支持 dailyfx.com/calendar 中的每个货币.
以下的代码段基于发布新闻的国家指定了交易的货币. 以下是货币列表: EUR, USD, JPY, GBP, CHF, AUD, CAD, NZD
if(stCurrency=="EUR" ){ordercurrency="EURUSD";} //交易 eurusd if(stCurrency=="USD" ){ordercurrency="EURUSD";} //交易 eurusd if(stCurrency=="JPY" ){ordercurrency="USDJPY";} //交易 usdjpy if(stCurrency=="GBP" ){ordercurrency="GBPUSD";} //交易 usdgbp if(stCurrency=="CHF" ){ordercurrency="USDCHF";} //交易 usdchf if(stCurrency=="AUD" ){ordercurrency="AUDUSD";} //交易 audusd if(stCurrency=="CAD" ){ordercurrency="USDCAD";} //交易 usdcad if(stCurrency=="NZD" ){ordercurrency="NZDUSD";} //交易 nzdusd
以下的代码段描述了EA在有可用的预测经济数据, 等待真实经济数据时, 如何做出交易决定.
当预测数据不可用时, EA使用之前的数据来进行交易.
以下代码段解释了如何基于预测数据与真实数据执行交易. 当EA根据之前与实际经济数据来作交易决定的算法是一样的.
if(StringToDouble(stActual)>StringToDouble(stForecast)) { Aert("Stronger(actual vs forecast): "+stCurrency+" "+"Time: "+stTime); int total=OrdersTotal(); for(int cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); //check opened orders if(OrderComment()==stCurrency+stActual+stForecast+"BUY"|| OrderComment()==stCurrency+stActual+stForecast+"SELL") { FileClose(file);Comment("\n"+"Live Trade Open"+OrderTicket());return(0); } } int historytotal=OrdersHistoryTotal(); for(cnt=0;cnt<historytotal;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY); //check opened orders if(OrderComment()==stCurrency+stActual+stForecast+"BUY"|| OrderComment()==stCurrency+stActual+stForecast+"SELL"){ FileClose(file);Comment("\n"+"Trade Executed"+OrderTicket());return(0); } } if(stCurrency=="EUR"||stCurrency=="GBP"||stCurrency=="AUD") { double ask=MarketInfo(ordercurrency,MODE_ASK); double point1=MarketInfo(ordercurrency,MODE_POINT); OrderSend(ordercurrency,OP_BUY,lot_p,ask,3,ask-(risk*point1), ask+reward*risk*point1),stCurrency+stActual+stForecast+"BUY");} if(stCurrency=="CHF"||stCurrency=="CAD"|| stCurrency=="NZD"||stCurrency=="JPY"||stCurrency=="USD") { double bid=MarketInfo(ordercurrency,MODE_BID); double point2=MarketInfo(ordercurrency,MODE_POINT); OrderSend(ordercurrency,OP_SELL,lot_p,bid,3,bid+risk*point2), bid-(reward*risk*point2),stCurrency+stActual+stForecast+"SELL");}
第一: EA对每个新闻事件只会执行一个订单, 所以首先需要检查是否已经执行了订单, 如果已经建立了订单, EA就退出.
第二: EA判断订单是否已经执行并关闭, 如果已经执行并关闭, 无论获利还是亏损, EA也退出.
这两项检查确保不会有重复的订单, 这样EA就对一个新闻事件只会进行一次交易.
然后, 它判断数据是哪个国家发布的, 然后当经济数据发布时使用OrderSend函数来进行交易.
以上代码的作用是: 当真实数据大于预测数据, 还有真实数据小于预测数据, 算法是相同的, 差别只是交易的方向.
比较以前数据和实际数据的算法也是相同的.
EA比较 (真实数据与预测数据), 或者 (实际数据与以前数据), 新闻数据差距的百分比决定了交易的手数.
以下代码段展示了EA如何计算差距百分比, 并指定手数大小, 手数大小是外部变量, 可以修改, 以支持不同的经纪商.
当用户把EA应用于图表时可以修改手数. 默认的手数是 (0.01, 0.02, 0.03...0.17).
double percent_d_AF=MathAbs((MathAbs(StringToDouble(stActual)- StringToDouble(stForecast))/StringToDouble(stForecast))*100); double lot_p=0; if((percent_d_AF>0 && percent_d_AF<=3)){lot_p=lot1;}//0.1 手 if((percent_d_AF>3 && percent_d_AF<=6)){lot_p=lot2;}//0.2 手 if((percent_d_AF>6 && percent_d_AF<=9)){lot_p=lot3;}//0.3 手 if((percent_d_AF>9 && percent_d_AF<=12)){lot_p=lot4;}//0.4 手 if((percent_d_AF>12 && percent_d_AF<=15)){lot_p=lot5;}//0.5 手 if((percent_d_AF>15 && percent_d_AF<=18)){lot_p=lot6;}//0.6 手 if((percent_d_AF>18 && percent_d_AF<=21)){lot_p=lot7;}//0.7 手 if((percent_d_AF>21 && percent_d_AF<=24)){lot_p=lot8;}//0.8 手 if((percent_d_AF>24 && percent_d_AF<=27)){lot_p=lot9;}//0.9 手 if((percent_d_AF>27 && percent_d_AF<=30)){lot_p=lot10;}//1 手 if((percent_d_AF>30 && percent_d_AF<=40)){lot_p=lot11;}//2 手 if((percent_d_AF>40 && percent_d_AF<=50)){lot_p=lot12;}//3 手 if((percent_d_AF>50 && percent_d_AF<=60)){lot_p=lot13;}//4 手 if((percent_d_AF>60 && percent_d_AF<=70)){lot_p=lot14;}//5 手 if((percent_d_AF>70 && percent_d_AF<=80)){lot_p=lot15;}//6 手 if((percent_d_AF>80 && percent_d_AF<=90)){lot_p=lot16;}//7 手 if((percent_d_AF>90 && percent_d_AF<=100)){lot_p=lot17;}//8 手 if((percent_d_AF>100)) {lot_p=lot18;}//8 手
图表信息:

基础新闻数据的屏幕截图
当EA首先应用于图表时, 您可以设置 "xTime", "risk", "reward", "MagicNumber", "enable_close_time", "wait_time" 并指定您的最小和最大手数大小, 确保文件已经正确安装到默认位置.
EA将下载 dialyfx 日历, 并确定下一个是什么新闻事件. 它将会以注释的方式在图表上显示以下数据: 日期(Date), 时间(Time), 时区(TimeZone), 货币(Currency), 描述(Description), 重要性(Importance), 实际数据(Actual), 预测数据(Forecast), 以及之前数据(Previous)的新闻数据, 如上图所示.
在上图中, EA正在等待将要在 2:00AM 发布的新闻事件, 您可以看到, 之前经济数据已经知道了 (73,5%), 所以EA在等待真实数据. 当经济数据将要发布时, EA会比较数据, 根据之前与实际的经济数据来做出交易的决定.
最后, EA会从新闻事件计划的发布时间开始, 每分钟下载日历数据.
本EA根据 dailyfx.com/calendar 上以CSV格式发布的每个经济事件进行交易.
日历是使用"get right"程序下载的.
当新闻数据计划发布时, EA每隔一分钟下载日历数据.
EA分析日历并确定下一个将要到来的新闻事件, 然后等待新闻发布27分钟.
一旦经济数据发布, 它判断它是 (真实与预测) 还是 (真实与过去) 的数据.
EA会确定手数大小, 交易的货币, 以及根据经济日历事件进行交易的方向, 这些数据当EA运行时也可以在图表上找到.
订单以 1:3 的风险/回报比例执行.
EA设置为每个新闻事件只执行一个订单. 如果 "enable_close_time" 被设为 "true" 的值, EA会等待在 "wait_time" 中指定的分钟数, 然后关闭订单.
请记住遵守以下链接中的指导 /zh/articles/1502, 这样日历就能正确下载, 而您的经纪商时间也能正确设置, 因为需要处理的新闻, dailyfx.com/calendar 的数据时区是GMT.
如果您有任何问题, 建议或批评, 请写下您的评论.由MetaQuotes Ltd译自英文
原代码: /en/code/8491
分形自适应移动均线
2005 年 10 月期刊 - "FRAMA - 分形自适应移动均线" 长度将被强制为偶数。. 奇数将被上调到临近的偶数。
Upload Export
UploadExport 脚本程序是一个通用的程序工具. 它可以减轻每天使用ELWAVE程序进行波段分析的分析员和交易者的工作.