- //+------------------------------------------------------------------+
- //| MT4多空各开一单EA框架模板.mq4 |
- //| |
- //| http://www.lh321.com |
- //+------------------------------------------------------------------+
- //======================================
- //---软件界面参数设置
- #property copyright "+点击【领汇网】查看更多实用软件"
- #property link "http://www.lh321.com"
- #property description "【领汇网】 :www.lh321.com"
- #property description "【软件版本】:多空各开一单EA框架模板"//软件版本【界面显示】
- #property description "【授权期限】:永久"
- #property version " 【领汇网】www.lh321.com" //软件版本【标题显示】
- #property description "【作者 QQ】:83898578"
- #property description "【作者Q群】:34604068"
- #property description "【E A简介】:(EA)启动自动多空各下一单,同时设置止损止盈!"
- #property description "【软件性质】:本软件由领汇网编译优化,免费发行使用,未经授权,禁止商业化!"
- #property strict //通过该指令编译模式严谨控制所有的错误
- //======================================
- input double Lots =0.1; //【手数】手数设置
- input double stoploss = 300; //【止损】输入100等于10点距离
- input double takeprofit = 600; //【止盈】输入100等于10点距离
- input string comment_Buy = "多单"; //【多单注释】
- input string comment_Sell = "空单"; //【空单注释】
- input int magic = 123; //【订单批号】
- //+------------------------------------------------------------------+
- //| Expert initialization function |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //---
-
- //---
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Expert deinitialization function |
- //+------------------------------------------------------------------+
- void OnDeinit(const int reason)
- {
- //---
-
- }
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- //---
- buy(Lots,stoploss,takeprofit,comment_Buy,magic); //开多单:
- sell(Lots,stoploss,takeprofit,comment_Sell,magic); //开空单:
- }
- //+------------------------------------------------------------------+
- //开多单扫描
- bool buy(double lots,double zhisun, double zhiying,string zhushi,int haoma) //扫描开出的单子
- {
- bool b=false; bool a=0;
- int t=OrdersTotal();
- for(int i=0;i<t;i++)
- {
- if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
- {
- if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderComment()==zhushi && OrderMagicNumber()==haoma)
- {
- b=true;
- break;
- }
- }
- }
- if(b==false)
- {
- if(zhisun!=0 && zhiying!=0)
- {
- a=OrderSend(Symbol(),OP_BUY,lots,Ask,0,Ask-zhisun*Point,Ask+zhiying*Point,zhushi,haoma,Red);
- }
- else if(zhisun==0 && zhiying!=0)
- {
- a=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,Ask+zhiying*Point,zhushi,haoma,Red);
- }
- else if(zhisun==0 && zhiying==0)
- {
- a=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,zhushi,haoma,Red);
- }
- else if(zhisun!=0 && zhiying==0)
- {
- a=OrderSend(Symbol(),OP_BUY,lots,Ask,0,Ask-zhisun*Point,0,zhushi,haoma,Red);
- }
- }
-
- return(a);
- }
-
- //开空单扫描
- bool sell(double lots,double sl,double tp, string com,int sellmagic) //扫描开出的单子
- {
- int a=0;
- bool zhaodan=false;
- //获取开单信息
- for(int i=0;i<OrdersTotal();i++)
- {
- if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
- {
- string zhushi=OrderComment();//注释
- int ma=OrderMagicNumber();//标记
- if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && zhushi==com && ma==sellmagic)
- {
- zhaodan=true;
- break;
- }
- }
- }
- if(zhaodan==false)
- {
- if(sl==0 && tp!=0)
- {
- a=OrderSend(Symbol(),OP_SELL,lots,Bid,50,0,Bid-tp*Point,com,sellmagic,0,White);
- }
- else if(sl!=0 && tp==0)
- {
- a=OrderSend(Symbol(),OP_SELL,lots,Bid,50,Bid+sl*Point,0,com,sellmagic,0,White);
- }
- else if(sl==0 && tp==0)
- {
- a=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,com,sellmagic,0,White);
- }
- else if(sl!=0 && tp!=0)
- {
- a=OrderSend(Symbol(),OP_SELL,lots,Bid,0,Bid+sl*Point,Bid-tp*Point,com,sellmagic,0,White);
- }
- }
-
- return(a);
- }
复制代码
|