论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
  • 1
  • 2
前往
共 32 条
查看:5674回复:31
关于MT软件的人工智能实践小小篇
楼主发表于:2004-01-04 17:59只看该作者倒序浏览
1楼 电梯直达
电梯直达
文前说明 :本资料选自某交易平台的说明 .请勿授权而转载. 初步创建一简易的人工智能系统 让我们将MACD指标同获利能力、支撑移动止损位以及操作安全等因素结合起来考虑以创建人工智能系统。下面的例子是开立和控制一个单独的头寸。 交易原则: .做多(买入)信号—即当MACD 指针是在0轴在以下,为向上的趋势并与向下的信号线相交 .做空(卖出) 信号—即当MACD 指针是在0轴以上,为向下趋势并与向上的信号线相交 .多头平仓信号—即执行限价平仓指令或移动止损指令以获得利润或者在MACD指针与信号线相交(MACD指针在0轴以上且为向下趋势并与向上趋势的信号线相交)时平仓 .空头平仓信号—即执行限价平仓指令或移动止损指令以获得利润或者在MACD指针与信号线相交(MACD指针在0轴以下且为向上趋势并与向下趋势的信号线相交)时平仓 [ 此消息由 逆风飞扬 在 2004-01-05.02:15:00 编辑过 ]
TK29帖子1楼右侧xm竖版广告90-240
个性签名

韬客社区www.talkfx.co

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告
楼主发表于:2004-01-04 18:11只看该作者
10楼
第一步:撰写人工智能系统说明 将鼠标指在导航窗口的人工智能系统,点击鼠标右键在弹出的菜单中CREATE A NEW EXPERT(创建一个智能系统)命令. 正在初始化的WISARD OF EXPERT ADVISOR 会问你是否要输入数据.在弹出的窗口中你得写下NAME名字(人工智能系统的名字) 、AUTHOR作者、与你的网址链接、须知—人工智能系统的测试样本.你也可以设定你想要的Lots(交易单位), Stop Loss(止损点), Take Profit(平仓) 和 Trailing Stop(移动止损)的默认值 http://www.talkforex.com/old-attachments/2004812194519.jpg [此帖子已被 老正 在 2004-8-12 19:45:22 编辑过]
楼主发表于:2004-01-04 18:12只看该作者
11楼
http://www.talkforex.com/old-attachments/2004812194817.jpg [此帖子已被 老正 在 2004-8-12 19:48:20 编辑过]
楼主发表于:2004-01-04 18:13只看该作者
12楼
第二步:创立程序的初步结构 测试系统的代码仅仅为几页纸,即使是这几页纸仍然是难以理解的,特别是在我们这些不是专业的程序员的眼里是非常难的.不然,我们也不必写下这段说明,不是吗? 为了了解标准的人工智能系统的结构,我们来看一下下面的解释: 1.初始资料检查 .检查图表,图表上棍的数量 .检查外部变数值:LOTS,S/L,T/P,T/S 2.设置为快速数据存取的内部变量 3检查交易终端—是否有空间?如果有,然后 .检查账户中的可用资金 .是否可以做多(买入) .建仓买入和平仓 .是否可以做空(卖出) .建仓卖出和平仓 4. 定期控制已开立的头寸 ..若是多头合约 .是否要平仓 .是否要重新设定移动止损点 ..若是空头合约 .是否要平仓 .是否要重新设定移动止损点 这是相对简单的样板,仅仅只有4个主要单元.
个性签名

韬客社区www.talkfx.co

广告
论坛谏言--外汇交易不应是你投资的全部,交易外汇也不应是你生活的全部
楼主发表于:2004-01-04 18:13只看该作者
21楼
现在我们来试着逐渐将结构表中的每一部分的代码做出来: 1.初始资料检查 这一块的数据通常是经过稍稍修改后从一个系统移至另一系统的—这实际上是一单元检查. If Bars<;200 Then Exit; // the chart has less than 200 bars - exit If TakeProfit<;10 Then Exit; // wrong takeprofit parameters 2设置为快速数据存取的内部变量 在程序代码中,有的是经常需要存取的指示值和操做的计算值.为了简化译码和加速存取,数据最初便在内部变数中嵌套进去 .MacdCurrent=iMACD(12,26,9,MODE_MAIN,0); // MACD value on the current bar MacdPrevious=iMACD(12,26,9,MODE_MAIN,1);// MACD value on the previous bar SignalCurrent=iMACD(12,26,9,MODE_SIGNAL,0); // Signal Line value on the current bar SignalPrevious=iMACD(12,26,9,MODE_SIGNAL,1);// Signal Line value on the previous bar MaCurrent=iMA(MATrendPeriod,MODE_EMA,0);// moving average value on the current bar MaPrevious=iMA(MATrendPeriod,MODE_EMA,1); // moving average value on the previous bar 现在,我们以在程序中简单的写入字符 MacdCurrent代替晦涩难懂的iMACD(12,26,9,MODE_MAIN,0).所有的人工智能系统中的变量都依据MQL II语言进行基本的解释. var: MacdCurrent(0), MacdPrevious(0), SignalCurrent(0), SignalPrevious(0); var: MaCurrent(0), MaPrevious(0); MQL II语言还另外推出一种的用户自定义变量,它可以在程序外设定而无须任何系统程序下的源程序正文的参考.这个特点使程序更具灵活性MATrendPeriod变量就是一个这种类型的用户自定义变量,因此,我们在程序的开头加入这段说明. defines: MATrendPeriod(56); 3. 检查交易终端是否有空间?如果有,然后 在我们的人工智能系统中,我们只能使用现时头寸而不能操作延迟的买卖盘.为了安全起见,我们介绍一种核对过去交易终端已下买卖盘的程序. If TotalTrades<;1 then // no opened orders identified { 3.检查: 账户的可用资金……. 在分析市场状况之前最好先检查一下你的账户的资金情况, 以确保账户中有开立头寸的资金. If FreeMargin<;1000 then Exit;// no funds – exit . 是否可以做多(买入) 买入的条件信号:MACD指标在0轴以下,为向上趋势且与向下趋势的信号线相交。这就是我们在MQL II语言中如何描述它的(说明我们如何操作过去在变量中存入的指示值) If MacdCurrent<;0 and MacdCurrent>;SignalCurrent and MacdPrevious<;SignalPrevious and// a cross-section exists Abs(MacdCurrent)>;(MACDOpenLevel*Point) and // the indicator plotted a decent 'hillock' MaCurrent>;MaPrevious then// 'bull' trend { SetOrder(OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,RED); // executing Exit; // exiting, since after the execution of a trade // there is a 10-second trading timeout }; 前面我们提到了一种监控图表中所要显示“小丘”的大小的一种方法。MACDOpenLevel 变量是自定义变量,它可以不影响程序正本而改变同时,还确保了更多的灵活性。在程序的初始,我们加入一段这个变量的描述. defines: MACDOpenLevel(3), MACDCloseLevel(2); 是否可以做空(卖出)? 卖出的条件信号: MACD指标在0轴以上,为向下趋势且与向上趋势的信号线相交.符号如下: If MacdCurrent>;0 and MacdCurrent<;SignalCurrent and MacdPrevious>;SignalPrevious and MacdCurrent>;(MACDOpenLevel*Point) and MaCurrent<;MaPrevious then { SetOrder(OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,RED); // executing Exit; // exiting }; Exit; // no new positions opened - just exit }; 4.定期控制已开立的头寸 for cnt=1 to TotalTrades { if OrderValue(cnt,VAL_TYPE)<;=OP_SELL and // is it an open position? OrderValue(cnt,VAL_SYMBOL)=Symbol then// position from "our" chart? { CNT是周期变量,是在程序之开端进行描述的,方式如下: var: Cnt(0); . 若是买入合约 If OrderValue(cnt,VAL_TYPE)=OP_BUY then // long position opened { . 是否需平仓? 平仓的条件信号: MACD指针与信号线相交,MACD指针在0轴以上,为向下趋势且与向上趋势的信号线相交. If MacdCurrent>;0 and MacdCurrent<;SignalCurrent and MacdPrevious>;SignalPrevious and MacdCurrent>;(MACDCloseLevel*Point) then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet); Exit; // exit }; . 是否需要重新设定移动止损点? 我们仅在持仓并已超过移动止损点数点还获利的情况下设定移动止损点, 即新的移动止损点比以前的更精确时才重设. If TrailingStop>;0 then // if trailing stops are used { If (Bid-OrderValue(cnt,VAL_OPENPRICE))>;(Point*TrailingStop) then { If OrderValue(cnt,VAL_STOPLOSS)<;(Bid-Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red); Exit; }; }; . 若是空头合约 else // otherwise it is a short position { . 是否需平仓? 平仓的条件信号: MACD指针与信号线相交,MACD指针在0轴以下,为向上趋势且与向下趋势的信号线相交. If MacdCurrent<;0 and MacdCurrent>;SignalCurrent and MacdPrevious<;SignalPrevious and Abs(MacdCurrent)>;(MACDCloseLevel*Point) then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); Exit; // exit }; .是否需要重新设定移动止损点? 我们仅在持仓并已超过移动止损点数点还获利的情况下设定移动止损点, 即新的移动止损点比以前的更精确时才重设. If TrailingStop>;0 then// the user has put a trailing stop in his settings {// so, we set out to check it If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>;(Point*TrailingStop) then { If OrderValue(cnt,VAL_STOPLOSS)=0 or OrderValue(cnt,VAL_STOPLOSS)>;(Ask+Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red); Exit; }; }; }; // end. Closing all the curly bracket which remain open. }; }; }; 这样,跟着这套初学渐进程序,我们就学会了编写自己的人工智能系统
楼主发表于:2004-01-04 18:15只看该作者
2楼
第三步:将所有程序代码集合起来 我们将前面所有的代码集合过来 defines: MACDOpenLevel(3),MACDCloseLevel(2); defines: MATrendPeriod(56); var: MacdCurrent(0),MacdPrevious(0),SignalCurrent(0),SignalPrevious(0); var: MaCurrent(0),MaPrevious(0); var: cnt(0); // initial data checks // it is important to make sure that the Expert Advisor runs on a normal chart and that // the user has correctly set the external variables (Lots, StopLoss, // TakeProfit, TrailingStop) // in our case we only check the TakeProfit If Bars<;200 or TakeProfit<;10 then Exit;// less than 200 bars on the chart // to simplify and speed up the procedure, we store the necessary // indicator data in temporary variables MacdCurrent=iMACD(12,26,9,0,MODE_MAIN); MacdPrevious=iMACD(12,26,9,1,MODE_MAIN); SignalCurrent=iMACD(12,26,9,0,MODE_SIGNAL); SignalPrevious=iMACD(12,26,9,1,MODE_SIGNAL); MaCurrent=iMA(MATrendPeriod,MODE_EMA,0); MaPrevious=iMA(MATrendPeriod,MODE_EMA,1); // now we have to check the status of the trading terminal. // we are going to see whether there are any previously opened positions or orders. If TotalTrades<;1 then {// there are no opened orders // just to be on the safe side, we make sure we have free funds on our account. // the "1000" value is taken just as an example, usually it is possible to open 1 lot If FreeMargin<;1000 then Exit;// no money - we exit // checking for the possibility to take a long position (BUY) If MacdCurrent<;0 and MacdCurrent>;SignalCurrent and MacdPrevious<;SignalPrevious and Abs(MacdCurrent)>;(MACDOpenLevel*Point) and MaCurrent>;MaPrevious then { SetOrder(OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,RED); // executing Exit; // exiting, since after the execution of a trade // there is a 10-second trading timeout }; // checking for the possibility of taking a short position (SELL) If MacdCurrent>;0 and MacdCurrent<;SignalCurrent and MacdPrevious>;SignalPrevious and MacdCurrent>;(MACDOpenLevel*Point) and MaCurrent<;MaPrevious then { SetOrder(OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,RED); // executing Exit; // exiting }; // here we completed the check for the possibility of opening new positions. // no new positions were opened and we simply exit the programme using the Exit command, as // there is nothing to analyze Exit; }; // we come over to an important part of the Expert Advisor - the control of open positions // 'it is important to enter the market correctly, but it is even more important to exit it...' for cnt=1 to TotalTrades { if OrderValue(cnt,VAL_TYPE)<;=OP_SELL and // is this an open position? OP_BUY or OP_SELL OrderValue(cnt,VAL_SYMBOL)=Symbol then// does the instrument match? { If OrderValue(cnt,VAL_TYPE)=OP_BUY then // long position opened { // we check - maybe, it's already time to close it? If MacdCurrent>;0 and MacdCurrent<;SignalCurrent and MacdPrevious>;SignalPrevious and MacdCurrent>;(MACDCloseLevel*Point) then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet); Exit; // exiting }; // we check - maybe, we already may or it's already time to set a trailing stop? If TrailingStop>;0 then// the user has put a trailing stop in his settings { // so, we set out to check it If (Bid-OrderValue(cnt,VAL_OPENPRICE))>;(Point*TrailingStop) then { If OrderValue(cnt,VAL_STOPLOSS)<;(Bid-Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red); Exit; }; }; }; } else // otherwise it is a long position { // we check - maybe, it's already time to close it? If MacdCurrent<;0 and MacdCurrent>;SignalCurrent and MacdPrevious<;SignalPrevious and Abs(MacdCurrent)>;(MACDCloseLevel*Point) then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); Exit; // exiting }; // we check - maybe, we already may or it's already time to set a trailing stop? If TrailingStop>;0 then// the user has put a trailing stop in his settings {// so, we set out to check it If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>;(Point*TrailingStop) then { If OrderValue(cnt,VAL_STOPLOSS)=0 or OrderValue(cnt,VAL_STOPLOSS)>;(Ask+Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red); Exit; }; }; }; }; }; }; // the end. 现在,我们只需给以下外部变量赋值就可以完成安装人工智能系统的全过程. LOTS=1,STOP LOSS(S/L)=0, TAKE PROFIT(T/P)=120(适用于一个小时的间 隔),TRAILING STOP(T/S)=30,当然你自己可以设定这些值. 按VERIFY按纽,若无别的错误就按SAVE按纽.
楼主发表于:2004-01-04 18:18只看该作者
13楼
现在,我们来编辑人工智能系统.在MQL编辑器点击顶端的VERIFY图示(像一张有检查标记的纸.)。 http://www.talkforex.com/old-attachments/2004812195038.jpg [此帖子已被 老正 在 2004-8-12 19:50:40 编辑过]
楼主发表于:2004-01-04 18:20只看该作者
14楼
第四步: 检测人工智能系统的历史资料 http://www.talkforex.com/old-attachments/2004812195123.jpg [此帖子已被 老正 在 2004-8-12 19:51:25 编辑过]
楼主发表于:2004-01-04 18:21只看该作者
24楼
我们已将人工智能系统编写完毕,现在我们已迫不及待地想用历史数据来对系统进行测试。让我们以EUR/USD的15分钟的间隔(大约4000棍)。为例, 打开交易平台中的EUR/USD15分钟图,用ATTACH TO A CHART命令将人工智能系统的MACD指针样本图粘贴在图表上(在导航窗口用鼠标选择MACD样本线, 点击鼠标右键选择所弹出菜单的命令). 然后,到系统设置里,在这我们可以改变预设变量和用户自定义变量,如LOTS、STOP LOSS、PROFIT、TRAILING STOP等. 为了让人工智能系统不仅只起到建议的作用,还能在营业账户上自动进行实时操作, 你需要击活ALLOWLIVETRADING按纽.现在,我们来进行历史数据的测试了,我们不改变设置,转接到STRATEGY TESTER标签,击活ALLOWS ON THE CHART标记(要能在图表上看到箭头),然后,按START按纽开始测试. http://www.talkforex.com/old-attachments/2004812195231.jpg [此帖子已被 老正 在 2004-8-12 19:52:33 编辑过]
楼主发表于:2004-01-04 18:23只看该作者
18楼
人工智能系统所有代码在Ready Expert Advisors页都可找到。 当你对人工智能系统作出修改时必须紧记: 修改和测试交易平台的人工智能系统时必须注意以下细节: .在建立仓位之前,你必须检查你账户上可用保证金的有效性。假如可用保证金不足时,则开仓请求将会失败。必须注意的是,为了达到测试的目的,可用保证金最少应在1000元,另一张单的测试价格也是1000元。 If FreeMargin <; 1000 Then Exit; // no funds - exit 当开仓、平仓或者修改已有部位或删除预先设定的部位(即是执行以下任何的操作:SetOrder, CloseOrder, ModifyOrder or DeleteOrder)时,建议使用人工智能系统的Exit语句来完成这部分的操作,这将有10秒钟的限定时间间隔来执行该项操作。注意,10秒钟的限定时间不适用于测试模式(你可以在一行中做几次交易),另外,假如不是用Exit语句来完成人工智能系统的上述交易操作,人工智能系统的测试结果将和真实交易不同。 SetOrder(OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,RED); // executing Exit;// exiting 为了防止在测试模式中用少于10秒的间隔来执行几项交易,你只需确保从上一次交易到下一次的交易已经超过10秒。 //making sure that the current time value is greater than 10 seconds since the execution of the last trade If CurTime >; LastTradeTime + 10 Then Begin SetOrder(OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,RED);// executing Exit; End; .历史数据可以用已引索的预设变量OPEN、 CLOSE、 HIGH、 LOW、 VOLUME来存取.在这种情况下,指数是指必须回头计算的周期数. // if the Close on the last bar is less than the Close on the last but one bar If Close[1] <; Close[2] Then Exit; . 交易平台中的人工智能系统支持4种模式: · OHLC 点(Open/High/Low/Close)模式. 因为系统在此的测试目的仅限于开盘价、收盘价、最高价、最低价,所以这个测试系统是相当快的.但是,这个测试结果与系统执行的实际交易的结果可能会不一样. . 每3点一次模式:在测试人工智能系统时,每增加三点就会加一个烛台图示 .每2点一次模式: 在测试人工智能系统时,每增加二点就会加一个烛台图示 . 每1点一次模式: 在测试人工智能系统时,每增加一点就会加一个烛台图,这种模式是最慢的但是测试结果是最接近人工智能系统的实际交易的结果的。(每10秒钟间隔的交易观察结果) . 在编写和检验一人工智能系统时,同测试其它的程序一样,有时, 需要输出一些额外的调试信息。MQL II语言就支持这类信息的输出 .ALERT函数将包含由用户自定义数据的对话框发送至屏幕 Alert("Free margin is ", FreeMargin); .COMMENT函数将由用户定义的数据放置在图表的左上角。“\N” 字符用于结束一行。 Comment("Free margin is ", FreeMargin, "\nEquity is ", Equity); .PRINT函数是将由用户定义的数据输至系统记录 Print("Total trades are ", TotalTrades, "; Equity is ", Equity, "; Credit is ", Credit); .PrintTrade函数是将指定的未平仓合约的具体细节从系统记录中输出 PrintTrade(1); .当 人工智能系统 已测试完毕,测试结果会以扩展名为.LOG的文件形式储藏在你安装該交易平台所在的目录的下级子目录中。如果你经常性地测试你的人工智能系统,别忘了定期删除log档,这种档往往会占用数兆字节。 [ 此消息由 逆风飞扬 在 2004-01-05.11:23:45 编辑过 ]
老正
注册时间2003-09-21
365热心助人奖
发表于:2004-01-05 01:37只看该作者
8楼
.............. 【动作】老正来回地踱着方步,陷入沉思中。
fforex
注册时间2004-07-17
发表于:2004-01-07 02:04只看该作者
15楼
Summary::::::::::-170 损失惨重呀!!! 【动作】fforex惊叫一声,吓了别人一大跳!【动作】fforex大叫:狼来了!狼来了!救命啊!救命啊!
楼主发表于:2004-01-07 08:39只看该作者
3楼
那有一口吃個大胖子的呀【动作】逆风飞扬惊讶得两眼瞪得贼大!
chenxing
注册时间2003-12-16
金融小小子
注册时间2004-03-09
汉唐投资
注册时间2004-03-22
发表于:2004-04-01 05:27只看该作者
4楼
好文章。【动作】汉唐投资抱拳团团一拜,讨好地说道:敝人对各位的景仰之情,有如涛涛江水连绵不绝。
ycai
注册时间2004-04-01
发表于:2004-04-02 07:02只看该作者
25楼
我将软件自带的一个例子macd sample 通过attach to a chart加载到图中,但是在图上没有什么反映啊?是不是到了一个进场点会出现一个符号呢?盼楼主帮助
luvalo
注册时间2004-02-29
发表于:2004-04-02 09:09只看该作者
23楼
有点耐心再看!【动作】luvalo张开双臂:来吧,小宝贝儿!让叔叔抱!
发表于:2004-04-10 07:13只看该作者
7楼
请问版主以及各位高手: 是否这个系统如果开发成功的话, 是否会自动帮我开仓或平仓啊?? 盼望您们的回复。
  • 1
  • 2
前往
共 32 条

本站免责声明:

1、本站所有广告及宣传信息均与韬客无关,如需投资请依法自行决定是否投资、斟酌资金安全及交易亏损风险;

2、韬客是独立的、仅为投资者提供交流的平台,网友发布信息不代表韬客的观点与意思表示,所有因网友发布的信息而造成的任何法律后果、风险与责任,均与韬客无关;

3、金融交易存在极高法律风险,未必适合所有投资者,请不要轻信任何高额投资收益的诱导而贸然投资;投资保证金交易导致的损失可能超过您投入的资金和预期。请您考虑自身的投资经验及风险承担能力,进行合法、理性投资;

4、所有投资者的交易帐户应仅限本人使用,不应交由第三方操作,对于任何接受第三方喊单、操盘、理财等操作的投资和交易,由此导致的任何风险、亏损及责任由投资者个人自行承担;

5、韬客不隶属于任何券商平台,亦不受任何第三方控制,韬客不邀约客户投资任何保证金交易,不接触亦不涉及投资者的任何资金及账户信息,不代理任何交易操盘行为,不向客户推荐任何券商平台,亦不存在其他任何推荐行为。投资者应自行选择券商平台,券商平台的任何行为均与韬客无关。投资者注册及使用韬客即表示其接受和认可上述声明,并自行承担法律风险。

版权所有:韬客外汇论坛 www.talkfx.com 联络我们:[email protected]