论坛全局菜单下方 - TICKMILL 285X70论坛全局菜单下方 - ThinkMarkets285X70论坛全局菜单下方 - 荔枝返现285X70论坛全局菜单下方 -  icmarkets285X70
查看:1512回复:3
vogood
注册时间2008-06-20
想求助秃鹫老师帮忙,写一个EA自动代码;
楼主发表于:2008-10-10 03:17只看该作者倒序浏览
1楼 电梯直达
电梯直达
//+------------------------------------------------------------------+ //| Designed by , China.com | //| Copyright 2007, 中国人 | //+------------------------------------------------------------------+ #property copyright "Copyright 2007, China.com " #property link "" #define MAGICMA 200708081234 //+------------------------------------------------------------------+ //| 注意没有指标文件那些property | //+------------------------------------------------------------------+ //在主函数和子函数外定义的变量为全局变量,全局变量的值在系统执行过程中是不变的,使用extern的作用是 //定义时对全局变量进行赋值,系统使用过程中,用户可以修改. extern int whichmethod = 1; //1~4 种下单方式 extern double TakeProfit = 100; //这个参数是止赢 extern double StopLoss = 20; //止损 extern double MaximumRisk = 0.3; //最大开仓量 extern double TrailingStop =25; //追止 extern int maxOpen = 3; //最多持仓限制 extern int maxLots = 5; //最多单仓限制 extern int bb = 0; //非零就跟踪止赢 extern double MATrendPeriod=26;//使用26均线 int i, p2, xxx,p1, res; double Lots; datetime lasttime; int init() //初始化 { Lots = 1; lasttime = NULL; return(0); } int deinit() { return(0); } //反初始化 //主程序 int start() { CheckForOpen(); if (bb>0) CTP(); //跟踪止赢 return(0); } //+------下面是各子程序---------------------------+ double LotsOptimized() //确定下单量,开仓调用 { double lot=Lots; int orders=HistoryTotal(); // history orders total int losses=0; // number of losses orders without a break //MarketInfo(Symbol(),MODE_MINLOT); //MarketInfo(Symbol(),MODE_MAXLOT); //MarketInfo(Symbol(),MODE_LOTSTEP); lot=NormalizeDouble(MaximumRisk * AccountBalance()/AccountLeverage(),1); if(lot<0.1) lot=0.1; if(lot>maxLots) lot=maxLots; return(lot); } //平仓持有的买单 void CloseBuy() { if (OrdersTotal( ) > 0 ) { for(i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderType()==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),Bid,3,White); Sleep(5000); } } } } //平仓持有的卖单 void CloseSell() { if (OrdersTotal( ) > 0 ) { for(i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),Ask,3,White); Sleep(5000); } } } } //判断买或卖或平仓 int buyorsell() //在这个函数计算设置你的交易信号 { double MacdCurrent, MacdPrevious, SignalCurrent; double SignalPrevious, MaCurrent, MaPrevious; MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1); SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0); SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0); MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1); if(iMA(NULL,0,fast,0,MODE_EMA,PRICE_CLOSE,i)>iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i) && iMA(NULL,0,fast,0,MODE_EMA,PRICE_CLOSE,i+1)iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i+1) && iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i+1)>iMA(NULL,0,slow,0,MODE_EMA,PRICE_CLOSE,i) //&& STEP=1 return (0); //不交易 } int nowbuyorsell = 0; void CheckForOpen() { if (Time[0] == lasttime ) return; //每时间周期检查一次 lasttime = Time[0]; nowbuyorsell = buyorsell(); //获取买卖信号 if (nowbuyorsell == 1) //买 先结束已卖的 CloseSell(); if (nowbuyorsell == -1) //卖 先结束已买的 CloseBuy(); if (TimeDayOfWeek(CurTime()) == 1) { if (TimeHour(CurTime()) < 3 ) return; //周一早8点前不做 } if (TimeDayOfWeek(CurTime()) == 5) { if (TimeHour(CurTime()) > 19 ) return; //周五晚11点后不做 } if (OrdersTotal( ) >= maxOpen) return ; //如果已持有开仓数达到最大,不做 if (nowbuyorsell==0) return; //不交易 TradeOK(); //去下单交易 } void TradeOK() //下单交易 { int error ; if (nowbuyorsell == 1) //买 { switch (whichmethod) { case 1: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);break; case 2: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-StopLoss*Point,0,"",MAGICMA,0,Blue); break; case 3: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);break; case 4: res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);break; default : res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);break; } if (res <=0) { error=GetLastError(); if(error==134)Print("Received 134 Error after OrderSend() !! "); // not enough money if(error==135) RefreshRates(); // prices have changed } Sleep(5000); return ; } if (nowbuyorsell == -1) //卖 { switch (whichmethod) { case 1: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red); break; case 2: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+StopLoss*Point,0,"",MAGICMA,0,Red); break; case 3: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,Bid-TakeProfit*Point,"",MAGICMA,0,Red); break; case 4: res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red); break; default : res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red); break; } if (res <=0) { error=GetLastError(); if(error==134) Print("Received 134 Error after OrderSend() !! "); // not enough money if(error==135) RefreshRates(); // prices have changed } Sleep(5000); return ; } } void CTP() //跟踪止赢 { bool bs = false; for (int i = 0; i < OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if (OrderType() == OP_BUY) { if ((Bid - OrderOpenPrice()) > (TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT))) { if (OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) { bs = OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(),0, Green); } } } else if (OrderType() == OP_SELL) { if ((OrderOpenPrice() - Ask) > (TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT))) { if ((OrderStopLoss()) > (Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT))) { bs = OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(),0, Tan); } } } } }
TK29帖子1楼右侧xm竖版广告90-240
个性签名

vogood

广告
TK30+TK31帖子一樓廣告
TK30+TK31帖子一樓廣告
vogood
注册时间2008-06-20
vogood
注册时间2008-06-20
楼主发表于:2008-10-10 03:24只看该作者
3楼
写一个EA 还真不容易! 写一个EA 还真不容易!
vogood
注册时间2008-06-20

本站免责声明:

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

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

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

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

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

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