一个神经网络的EA的示例备课讲稿_第1页
一个神经网络的EA的示例备课讲稿_第2页
一个神经网络的EA的示例备课讲稿_第3页
一个神经网络的EA的示例备课讲稿_第4页
一个神经网络的EA的示例备课讲稿_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Good is good, but better carries it.精益求精,善益求善。一个神经网络的EA的示例-一个神经网络的EA的示例(含源码)Combo_Right.mq4软件简介:去年年底结束的国际大赛的第一名为Better所夺得他采用的就是神经网络原理的EA这使得用神经网络方法做EA成为不少人关注的焦点这里翻译一篇采用神经网络做EA的不错的示例文章当然附有源码是吸引人的地方不过也许作者提出了研究神经网络EA的一些思考更为值得注意作者提出了1。“如果有飞机,为什么还要教人类去飞?”意思是研究是经网络不必从零起步。MT4里已有了不错的“遗传算法”文中介绍了如何利用MT4已有的“遗传算

2、法”2。大家都说做单子最重要的是“顺势而为”,但更需要解决的是“一个基于趋势的交易系统是不能成功交易在盘整(sidewaystrends),也不能识别市场的回调(setbacks)和逆转(reversals.,反向走势)!”这可是抓到不少人心中的“痒处”,有多少人不是到了该逆势时没转向而产生亏损呢?3。训练神经网络需要用多长的历史数据,提出了并不是用的历史数据越长越好,另外也不是训练的间隔越短越好,文中提出了什么情况下有需再训练它。等等。下面是译文和作者的源码Theproblemisstatedforthisautomatedtradingsystem(ATS)asfollows:(ATS)自

3、动的(智能的,采用神经网络的)交易系统的问题表述如下Letsconsiderwehaveabasictradingsystem-BTS.ItisnecessarytocreateandteachaneuralnetworkinorderittodothingsthatcannotbedonewiththeBTS.ThismustresultincreationofatradingsystemconsistingoftwocombinedandmutuallycomplementaryBTSandNN(neuralnetwork).如果我们有一个(BTS,basictradingsystem),

4、同时需要用创建一个神经网络系统并教会它做BTS所不能做的事,按这个思路就是要创建这样一个交易系统它由互相补充(配合)的两部分组成,BTS和NN(神经网络)。Or,theEnglishofthisis:Thereisnoneedtodiscoverthecontinentsagain,theywerealldiscovered.Whytoteachsomebodytorunfast,ifwehaveacar,ortofly,ifwehaveaplane?呃,英语说,我们不需要再去发现“新大陆”,它们是已经存在的东西!进一步说,如果我们已经有了汽车,那为什么还要教人如何跑得快?如果有飞机,为什么还

5、要教人类去飞?Oncewehaveatrend-followingATS,wejusthavetoteachtheneuralnetworkincountertrendstrategy.Thisisnecessary,becauseasystemintendedfortrend-basedtradingcannottradeonsidewaystrendsorrecognizemarketsetbacksorreversals.Youcan,ofcourse,taketwoATSes-atrend-followingoneandacountertrendone-andattachthemtot

6、hesamechart.Ontheotherhand,youcanteachaneuralnetworktocomplementyourexistingtradingsystem.一旦有一个趋势交易系统的ATS,我们仅需要教会这个神经网络如何逆势(反趋势)交易的策略。这一点是非常必要的,因为一个基于趋势的交易系统是不能成功交易在盘整(sidewaystrends),也不能识别市场的回调(setbacks)和逆转(reversals.,反向走势)!当然,你可以采用两个ATS,一个基于“趋势”,一个基于“反趋势”(逆向),然后把它们挂到同一图表上。另一个办法是,你能教会神经网络如何与你现有的系统“

7、互补地”协调工作!Forthispurpose,wedesignedatwo-layerneuralnetworkconsistingoftwoperceptronsinthelowerlayerandoneperceptronintheupperlayer.为实现这个目标,我们设计了一个两层的神经网络,下层有两个感知机(perceptrons)上层有一个感知机。Theoutputoftheneuralnetworkcanbeinoneofthesethreestates:这个神经网络的能输出下列三种状态之一Enteringthemarketwithalongposition(Entering

8、)市场是处在多向仓Enteringthemarketwithashortposition(Entering)市场是处在空向仓Indeterminatestate不确定的,(不明确的,模糊的)状态Actually,thethirdstateisthestateofpassingcontrolovertotheBTS,whereasinthefirsttwostatesthetradesignalsaregivenbytheneuralnetwork.实际上,第三种状态是就把控制权交给BTS,反之前两种状态是交易信号由神经网络给出。Theteachingoftheneuralnetworkisdi

9、videdintothreestages,eachstageforteachingoneperceptron.Atanystage,theoptimizedBTSmustbepresentforperceptronstoknowwhatitcando.神经网络的“教育”分成三步骤,每一步骤“教育”一个感知机,在任何一步骤,这个优化了的BTS必须存在为的是“感知机们”知道它自己能做什么。Theseparateteachingofperceptronsbyageneticalgorithmisdeterminedbythelackofthisalgorithm,namely:Theamountof

10、inputssearchedinwiththehelpofsuchalgorithmislimited.However,eachteachingstageiscoherentandtheneuralnetworkisnottoolarge,sothewholeoptimizationdoesnottaketoomuchtime.感知机们分别的“教育”由遗传算法来承担,由于这样的算法的缺乏,换句话说,搜索到的这样的算法有限,限制了“输入”(参数变量)的数量(借助这样算法得到的参数变量的值),然而,每一步骤的“教育”是密切配合补充的。(因此效果还是不错),这样这个神经网络不会太大,整个的优化也不会

11、耗费太多的时间。Theveryfirststage,precedingtheteachingofanNN,consistsinoptimizationoftheBTS.在“教育”NN之前的一步是对BTS进行优化。Inordernottoloseourselves,wewillrecordthestagenumberintheinputoftheATSidentifiedaspass.Identifiersofinputscorrespondingwiththestagenumberwillandinthenumberequaltothisstagenumber.为了不使我们自己也被搞糊涂了,我

12、们将已经测试通过的ATS的输入(参数变量)记录上(”通过”(pass)的步骤号(stagenumber).,输入s(参数变量)的标识符将和stagenumber(步骤号)一致(等同)。Thus,letsstartpreparationsforoptimizationandteachingtheNN.Letssettheinitialdepositas$1000000(inordernottocreateanartificialmargincallduringoptimization)andtheinputtobeoptimizedasBalanceinExpertAdvisorproperti

13、esonthetabofTestingintheStrategyTester,andstartgeneticalgorithm.这样,我们开始对这个NN进行优化和“教育”的准备。存入初始保证金为$100万(以便于在优化期间不产生人为的补充保证金的通知)。Input(参数变量)是按“余额”进行优化,设置EA的StrategyTester的测试的属性tab为Testing。开始运行遗传算法。LetsgototheInputstaboftheEAspropertiesandspecifythevolumeofpositionstobeopenedbyassigningthevalue1totheid

14、entifierlots.在这个EA的开仓量lots.的值设为1lot。Optimizationwillbeperformedaccordingtothemodel:Openpricesonly(fastestmethodtoanalyzethebarjustcompleted,onlyforEAsthatexplicitlycontrolbaropening),sincethismethodisavailableintheATSalgorithm.从这个ATS算法明确地有效开始,实施优化,所采用复盘模型是“仅用开盘价(以最快速的方法分析刚形成的柱线)”。Stage1ofoptimizatio

15、n.OptimizationoftheBTS:优化步骤1,BTS的优化Setthevalue1fortheinputpass.设置为1为这input(参数变量)“为通过”(theinputpass)。Wewilloptimizeonlyinputsthatcorrespondwiththefirststage,i.e.,thatendin1.Thus,wecheckonlytheseinputsforoptimization,anduncheckallothers.我们仅仅优化步骤1相关的那些inputs(参数变量),即,尾标为1的参数变量,于是,我们仅仅测试优化有关的inputs而不测试其他

16、的变量参数tp1-TakeProfitoftheBTS.Itisoptimizedwiththevalueswithintherangeof10to100,step1tp1,BTS的所取的止盈值(TakeProfit)。在step1,优化的值的范围在10到100,sl1-StopLossoftheBTS.Itisoptimizedwiththevalueswithintherangeof10to100,step1sl1,BTS的所取的止损值(StopLoss)。在step1,优化的值的范围在10到100。p1-periodofCCIusedintheBTS.Itisoptimizedwitht

17、hevalueswithintherangeof3to100,step1p1,用于BTS的CCI的周期值。在step1,优化的值的范围在3到100BelowaretheresultsoftheBTSoptimization:下面是BTS优化的结果Stage2.Teachingtheperceptronresponsibleforshortpositions:步骤2,“教育负责管“开空仓”(shortpositions)的感知机Setthevalue2(accordingtothestagenumber)fortheinputpass.根据步骤的步骤号,设置(input,参数变量)的pass的值

18、为2。Unchecktheinputscheckedforoptimizationinthepreviousstage.Justincase,saveinafiletheinputsobtainedatthepreviousstage.不测试那些已经测试过的优化了的以前步骤的inputs.(变量参数)。以防万一,保存以前步骤获得的inputs(变量参数值)到一个文件中去Checktheinputsforoptimizationaccordingtoourrule:theiridentifiersmustendin2:根据我们的规则,必须是测试那些是在尾标为2的inputs(变量参数)。x12,

19、x22,x32,x42-weightnumbersoftheperceptronthatrecognizesshortpositions.Itisoptimizedwiththevalueswithintherangeof0to200,step1x12,x22,x32,x42是识别并开空仓的感知机的权重,它们的值在step1时被优化在范围0to200tp2-TakeProfitofpositionsopenedbytheperceptron.Itisoptimizedwiththevalueswithintherangeof10to100,step1tp2(TakeProfit)是感知机所开的

20、仓的止盈值,它们的值在step1时被优化在范围10to100。sl2-StopLossofpositionsopenedbytheperceptron.Itisoptimizedwiththevalueswithintherangeof10to100,step1sl2(StopLos)在step1它是感知机所开的仓的止损值,被优化值的范围在10to100p2-theperiodofthevaluesofpricedifferencetobeanalyzedbytheperceptron.Itisoptimizedwiththevalueswithintherangeof3to100,step1

21、.p2感知机所分析的价格差的周期值(iiCCI()函数的一个参数period-Averagingperiodforcalculation),在step1它的值所优化的范围在3to100Letsstartteachingitusingoptimizationwithageneticalgorithm.Theobtainedresultsaregivenbelow:现在,开始用遗传算法来优化“教育”NN(让它“学习”市场),获得的结果如下Stage3.Teachingtheperceptronresponsibleforlongpositions:步骤3“教育”负责开多仓的感知机(“学习”市场)。

22、Setthevalue3(accordingtothestagenumber)fortheinputpass.设置值3(根据步骤的步骤号)说明这些input(变量参数)已经“通过”(theinputpass)Unchecktheinputscheckedforoptimizationinthepreviousstage.Justincase,saveinafiletheinputsobtainedatthepreviousstage.同样,不测试,那些已经测试过的优化了的,以前步骤的inputs.(变量参数值),以防万一,保存以前步骤获得的inputs.(变量参数值)到一个文件中去Checkt

23、heinputsforoptimizationaccordingtoourrule:theiridentifiersmustendin3:根据我们的规则,优化测试的inputs(变量参数值)必须是尾标为3的那些变量参数。x13,x23,x33,x43-weightnumbersoftheperceptronthatrecognizeslongpositions.Itisoptimizedwiththevalueswithintherangeof0to200,step1.x13,x23,x33,x43是识别多仓的感知机的权重,它们的值在step1时被优化时得到的范围在0to200tp3-Take

24、Profitofpositionsopenedbytheperceptron.Itisoptimizedwiththevalueswithintherangeof10to100,step1tp3(TakeProfit)是感知机所开的仓的“止盈值”,它的值在step1时被优化时的范围是在10to100。sl3-StopLossofpositionsopenedbytheperceptron.Itisoptimizedwiththevalueswithintherangeof10to100,step1sl3(StopLoss)是感知机所开的仓的“止盈值”,它们的值在step1时被优化为范围是10t

25、o100。p3-theperiodofthevaluesofpricedifferencetobeanalyzedbytheperceptron.Itisoptimizedwiththevalueswithintherangeof3to100,step1.p3-感知机所分析的价差的周期值。它在步骤1优化时得到的值的范围是3to100。Letsstartteachingitusingoptimizationwithageneticalgorithm.Theobtainedresultsaregivenbelow:启动采用遗传算法的优化来“教育”NN,所获得的结果如下Stage4(final).T

26、eachingthefirstlayer,i.e.,teachingtheperceptronthatisintheupperlayer:步骤4(最终步骤)“教育”第一层,即“教育”在上层的感知机。Setthevalue4(accordingtothestagenumber)fortheinputpass.根据步骤的步骤号,设置值4为输入通过(fortheinputpass)Unchecktheinputscheckedforoptimizationinthepreviousstage.Justincase,saveinafiletheinputsobtainedatthepreviousst

27、age.不测试那些在之前步骤已经测试过的优化了的“输入”(inputs)(意思是已经在之前步骤优化过的变量的参数值就不再优化它们了)。以防万一,将之前步骤获得的这些变量的参数值存到一个文件中去。Checktheinputsforoptimizationaccordingtoourrule:theiridentifiersmustendin4:根据我们的规则,只测试优化标识符最后位是4的那些inputs(变量的参数值)x14,x24,x34,x44-weightnumbersoftheperceptronofthefirstlayer.Itisoptimizedwiththevalueswith

28、intherangeof0to200,step1.x14,x24,x34,x44是第一层感知机参数的权重值。在步骤1时它们被优化的值的范围在0to200。p4-theperiodofthevaluesofpricedifferencetobeanalyzedbytheperceptron.Itisoptimizedwiththevalueswithintherangeof3to100,step1.p4被感知机分析的价差的值的周期。在步骤1它的值的范围被优化在3to100。Letsstartteachingitusingoptimizationwithageneticalgorithm.Theo

29、btainedresultsaregivenbelow:采用遗传算法来优化,启动“教育”来教它“学习”。所获得结果如下Thatsall,theneuralnetworkhasbeentaught.这就是全部,神经网络已经被“教育”了。TheATShasonemorenon-optimizableinput,mn-MagicNumber.ItistheidentifierofpositionsforatradingsystemnottomixitsorderswiththeordersopenedmanuallyorbyotherATSes.Thevalueofthemagicnumbermus

30、tbeuniqueandnotcoincidewiththemagicnumbersofpositionsthathavenotbeenopenedbythisspecificExpertAdvisor.这个ATS有一个不能被优化的input(参数)mn-MagicNumber.(魔法号)它是一个交易系统它所开的仓位的识别符,为的是不和手动开仓或其他ATSes开的仓位混淆。这个MagicNumber的值必须是唯一的并且和这个特别的ea尚未开仓的magicnumbers不一致。P.S.Thesizeoftheinitialdepositisfoundasthedoubledabsolutedra

31、wdown,i.e.,weconsidersomesafetyresourcesforit.出于保证有一些安全保险的考虑,初始保证金的金额设置是考虑为绝对最大回落的两倍TheEAgiveninthesourcecodesisnotoptimized.这个ea的源代码没有优化。Ifyouneedtoreplacethebuilt-inBTSwiththealgorithmofanothertradingsystem,youmustmodifythecontentsofthefunctionbasicTradingSystem().如果你需要置换嵌入另一个交易系统算法的BTS,你必须修改BTS功能

32、的内部。Inordernottoentertheinitialandthefinalvaluesandthevaluesofstepsforoptimization,youcantakethereadyfilecombo.set,placeitinthefoldertesterMT4,anduploadtotheEAspropertiesinTester.以便于不输入优化时的初值,终值和步长,你可采用已备好的combo.set文件,把它放置到MT4的tester目录并加载这个ea的属性(properties)到StrategyTester。Re-optimizationoftheEAistob

33、eperformedataweekend,i.e.,onSaturdayoronSunday,butonlyiftheresultsoftheprecedingweekwereunprofitable.Thepresenceoflossesmeansthatthemarkethaschanged,andthere-optimizationisnecessary.ThepresenceofprofitsmeansthattheATSdoesnotneedanyre-optimizationandrecognizesmarketpatternsquitewell.这个ea的再优化可在周末进行,即周

34、六和周日,但仅在前面一周的结果是不盈利的。亏损的出现意味着市场已经改变,于是需要重新优化,若是仍然获利意味着这个ATS不需要重新优化,它对市场目前的模型的识别继续有效!附源代码:/+-+/|Combo_Right.mq4|/|Copyright?2008,YuryV.Reshetov|/|/load/2-1-0-171|/+-+#propertycopyrightCopyright?2008,YuryV.Reshetov#propertylink/load/2-1-0-171/-inputparametersexterndoubletp1=50;externdoublesl1=50;exter

35、nintp1=10;externintx12=100;externintx22=100;externintx32=100;externintx42=100;externdoubletp2=50;externdoublesl2=50;externintp2=20;externintx13=100;externintx23=100;externintx33=100;externintx43=100;externdoubletp3=50;externdoublesl3=50;externintp3=20;externintx14=100;externintx24=100;externintx34=1

36、00;externintx44=100;externintp4=20;externintpass=1;externdoublelots=0.01;externintmn=888;staticintprevtime=0;staticdoublesl=10;staticdoubletp=10;/+-+/|expertstartfunction|/+-+intstart()if(Time0=prevtime)return(0);prevtime=Time0;if(!IsTradeAllowed()again();return(0);/-inttotal=OrdersTotal();for(inti=0;i0)ticket=OrderSend(Symbol(),OP_BU

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论