首页 > EA > EA入门

【外汇EA自动交易】如何编制外汇EA自动交易系统

以下是一些简单的源码,供参考学习。
 
    //+------------------------------------------------------------------+ //| designed by okwh, china | //| copyright 2007, okwh dxdcn | //| | //+------------------------------------------------------------------+
 
    #property copyright "copyright 2007 , dxd, china." #property link "" #define magicma 200610011231 //+------------------------------------------------------------------+
 
    //| 注意没有指标文件那些property | //+------------------------------------------------------------------+ extern int whichmethod = 1; //1~4 种下单方式 1 仅开仓, 2 有止损无止赢, 3 有止赢无止损, 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() //在这个函数计算设置你的交易信号 这里使用macd 和ma 做例子
 
    { 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(macdcurrent<0 && macdcurrent>signalcurrent && macdpreviousmaprevious) return (1);
 
    // 买 ma在上升,macd在0线上,并且两线上交叉 if(macdcurrent>0 && macdcurrentsignalprevious && macurrent

【版权声明】

本文仅代表作者观点,不代表本站立场。Fx263.com对文中陈述、观点判断保持中立,不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证,且不构成任何投资建议,请读者仅作参考,并自行承担全部风险与责任。Fx263.com作为信息内容发布平台,页面展示内容的目的在于传播更多信息,不代表Fx263.com立场;本站会员及自媒体人所发的稿件所载明的信息与本网无关,如文章涉及版权,请联系本站处理。

【风险提示】

请通过正规渠道参与外汇保证金交易。目前通过网络平台提供、参与外汇保证金交易均属非法。请提高意识,谨防损失!外汇、贵金属和差价合约(OTC场外交易)是杠杆产品,存在较高的风险,可能会导致亏损您的投资本金,请理性投资。

 

Fx263.com - 全球财经中文网

官方交流微信号:FX263cn注明来意

重要声明 | 本站内容不适用于中国大陆地区访客。

Powered By Fx263.com - 版权所有

大中华地区全球财经中文网

本站内容仅供参考盈亏自负

FX263网 - 全球财经中文网