MQL4上如何编写逐步平仓的EA 新评论 sunliang19 2013.10.22 03:16 请教个问题,我想写个能逐步平仓的EA,我的EA如下,但是测试后没有办法进行逐步平仓,请问原因在哪里 ,请大家指点 我设置了一个变量 TN,用于选定订单的位置 //+------------------------------------------------------------------+ //| 多空+分批止盈.mq4 | //| Copyright 2013, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" //2013-10-17 //指定订单平仓,输入订单编号 extern int TN=1; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if (OrderSelect(TN,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==10000) { if (Bid>=OrderOpenPrice()+490*Point && OrderLots()>=0.9) { OrderClose(TN,0.4,Bid,10,CLR_NONE); } if(Bid>=OrderOpenPrice()+690*Point && OrderLots()>=0.7) { OrderClose(TN,0.2,Bid,10,CLR_NONE); } if(Bid>=OrderOpenPrice()+900*Point && OrderLots()>=0.6)//隔20点 { OrderClose(TN,0.1,Bid,10,CLR_NONE); } if(Bid>=OrderOpenPrice()+1390*Point && OrderLots()>=0.5)//隔50点 { OrderClose(TN,0.1,Bid,10,CLR_NONE); } if(Bid>=OrderOpenPrice()+1990*Point && OrderLots()>=0.4)//隔60点 { OrderClose(TN,0.1,Bid,10,CLR_NONE); } if(Bid>=OrderOpenPrice()+2790*Point && OrderLots()>=0.3)//隔80点 { OrderClose(TN,0.1,Bid,10,CLR_NONE); } if(Bid>=OrderOpenPrice()+3790*Point)//隔100点 { OrderClose(TN,0.1,Bid,10,CLR_NONE); } if((TimeCurrent()-OrderOpenTime()>=1000*60*60*24*2) && (Bid-OrderOpenPrice()<=100*Point) && OrderLots()>=0.7)//开单后过两天,平仓手数不超过0.5,价格再次回到开仓价格上方10点 { OrderClose(TN,0.4,Bid,10,CLR_NONE); } } if (OrderSelect(TN,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==10000) { if(Ask<=OrderOpenPrice()-490*Point && OrderLots()>=0.9) { OrderClose(TN,0.4,Ask,10,CLR_NONE); } if(Ask>=OrderOpenPrice()-690*Point && OrderLots()>=0.7) { OrderClose(TN,0.2,Ask,10,CLR_NONE); } if(Ask>=OrderOpenPrice()-900*Point && OrderLots()>=0.6)//隔20点 { OrderClose(TN,0.1,Ask,10,CLR_NONE); } if(Ask>=OrderOpenPrice()-1390*Point && OrderLots()>=0.5)//隔50点 { OrderClose(TN,0.1,Ask,10,CLR_NONE); } if(Ask>=OrderOpenPrice()-1990*Point && OrderLots()>=0.4)//隔60点 { OrderClose(TN,0.1,Ask,10,CLR_NONE); } if(Ask>=OrderOpenPrice()-2790*Point && OrderLots()>=0.3)//隔80点 { OrderClose(TN,0.1,Ask,10,CLR_NONE); } if(Ask>=OrderOpenPrice()-3790*Point)//隔100点 { OrderClose(TN,0.1,Ask,10,CLR_NONE); } if((TimeCurrent()-OrderOpenTime()>=1000*60*60*24*2) && (OrderOpenPrice()-Ask<=100*Point) && OrderLots()>=0.7)//开单后过两天,平仓手数不超过0.4,价格再次回到开仓价格上方10点 { OrderClose(TN,0.4,Ask,10,CLR_NONE); } } return(0); } //+------------------------------------------------------------------+ EA: Lucky 请大家给我看看,这个简单的系统不能编译是什么原因? [警告关闭!]任何新手问题,为了不给论坛添乱。专业人士,不要走过。没有你,哪里都不能去。 [删除] 2014.12.17 14:20 #1 现在可以了吗?可以之后告诉我。QQ1109886137 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
请教个问题,我想写个能逐步平仓的EA,我的EA如下,但是测试后没有办法进行逐步平仓,请问原因在哪里 ,请大家指点
我设置了一个变量 TN,用于选定订单的位置
//+------------------------------------------------------------------+
//| 多空+分批止盈.mq4 |
//| Copyright 2013, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//2013-10-17
//指定订单平仓,输入订单编号
extern int TN=1;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if (OrderSelect(TN,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==10000)
{
if (Bid>=OrderOpenPrice()+490*Point && OrderLots()>=0.9)
{
OrderClose(TN,0.4,Bid,10,CLR_NONE);
}
if(Bid>=OrderOpenPrice()+690*Point && OrderLots()>=0.7)
{
OrderClose(TN,0.2,Bid,10,CLR_NONE);
}
if(Bid>=OrderOpenPrice()+900*Point && OrderLots()>=0.6)//隔20点
{
OrderClose(TN,0.1,Bid,10,CLR_NONE);
}
if(Bid>=OrderOpenPrice()+1390*Point && OrderLots()>=0.5)//隔50点
{
OrderClose(TN,0.1,Bid,10,CLR_NONE);
}
if(Bid>=OrderOpenPrice()+1990*Point && OrderLots()>=0.4)//隔60点
{
OrderClose(TN,0.1,Bid,10,CLR_NONE);
}
if(Bid>=OrderOpenPrice()+2790*Point && OrderLots()>=0.3)//隔80点
{
OrderClose(TN,0.1,Bid,10,CLR_NONE);
}
if(Bid>=OrderOpenPrice()+3790*Point)//隔100点
{
OrderClose(TN,0.1,Bid,10,CLR_NONE);
}
if((TimeCurrent()-OrderOpenTime()>=1000*60*60*24*2) && (Bid-OrderOpenPrice()<=100*Point) && OrderLots()>=0.7)//开单后过两天,平仓手数不超过0.5,价格再次回到开仓价格上方10点
{
OrderClose(TN,0.4,Bid,10,CLR_NONE);
}
}
if (OrderSelect(TN,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==10000)
{
if(Ask<=OrderOpenPrice()-490*Point && OrderLots()>=0.9)
{
OrderClose(TN,0.4,Ask,10,CLR_NONE);
}
if(Ask>=OrderOpenPrice()-690*Point && OrderLots()>=0.7)
{
OrderClose(TN,0.2,Ask,10,CLR_NONE);
}
if(Ask>=OrderOpenPrice()-900*Point && OrderLots()>=0.6)//隔20点
{
OrderClose(TN,0.1,Ask,10,CLR_NONE);
}
if(Ask>=OrderOpenPrice()-1390*Point && OrderLots()>=0.5)//隔50点
{
OrderClose(TN,0.1,Ask,10,CLR_NONE);
}
if(Ask>=OrderOpenPrice()-1990*Point && OrderLots()>=0.4)//隔60点
{
OrderClose(TN,0.1,Ask,10,CLR_NONE);
}
if(Ask>=OrderOpenPrice()-2790*Point && OrderLots()>=0.3)//隔80点
{
OrderClose(TN,0.1,Ask,10,CLR_NONE);
}
if(Ask>=OrderOpenPrice()-3790*Point)//隔100点
{
OrderClose(TN,0.1,Ask,10,CLR_NONE);
}
if((TimeCurrent()-OrderOpenTime()>=1000*60*60*24*2) && (OrderOpenPrice()-Ask<=100*Point) && OrderLots()>=0.7)//开单后过两天,平仓手数不超过0.4,价格再次回到开仓价格上方10点
{
OrderClose(TN,0.4,Ask,10,CLR_NONE);
}
}
return(0);
}
//+------------------------------------------------------------------+