净值监控指标,时刻关注你的账户
给出源码,你们可以看看//+------------------------------------------------------------------+
//| 净值监控V1.mq4 |
//| Copyright 2012, Goddz Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Goddz Corp."
extern int参考净值 =0; //当净值小于此值时全平全撤 或 警报提醒
extern bool 全平全撤 = true;//true 表示净值达到后全平,false表示净值达到后只报警提示
int preEquity = 0;
int iniEquity = 0;
bool isAlertOn = true;
datetime closetime = 0;
bool isCloseOk = false;
int id = 0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
Alert("***------------------------。");
Alert("***------------------------。");
if (参考净值 > AccountEquity())
{
Alert("***参考净值不能大于当前净值。");
参考净值 = 0;
return(0);
}
if (preEquity != 参考净值)
{
Alert("***修改参考净值为:", 参考净值);
closetime = 0;
preEquity = 参考净值;
}
iniEquity = AccountEquity();
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if (参考净值 > 0 && AccountEquity() < 参考净值 && closetime == 0) //iniEquity >= 参考净值 &&
{
closetime = TimeCurrent(); //记录信息出现时间
isCloseOk = false;
Print("***净值达到设定值***", AccountEquity());
id = 0;
}
if (closetime > 0)
{
if (全平全撤)
{
if (!isCloseOk)
{
CloseAndDeleteAll();
if (OrdersTotal() == 0)
{
isCloseOk = true;
}
}
if (isCloseOk)
{
id++;
Alert("***净值达到设定值,请重新初始化参考净值*** ", id);
}
}
else
{
id++;
Alert("***净值达到设定值***", id);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
void CloseAndDeleteAll()
{
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
int ticket = OrderTicket();
bool ret = true;
if (OrderType() == OP_BUY)
{
ret = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 1000, CLR_NONE);
}
else if (OrderType() == OP_SELL)
{
ret = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 1000, CLR_NONE);
}
else if (OrderType() > OP_SELL)
{
ret = OrderDelete( OrderTicket() );
}//挂单
if (ret)
{
break;
}
//失败
IsContinueByErrcode( GetLastError(), ticket);
}
}//for
RefreshRates();
}
bool IsContinueByErrcode( int errCode, int ticket)
{
if (isAlertOn)
{
switch ( errCode )
{
case 129: if (isAlertOn) Alert(Symbol() + "-错误:无效的价格,交易失败.", " 定单号:" + ticket);break;
case 131: if (isAlertOn) Alert(Symbol() + "-错误:无效的交易量,交易失败.", " 定单号:" + ticket);break;
case 134: if (isAlertOn) Alert(Symbol() + "-错误:资金不足,交易失败.", " 定单号:" + ticket);break;
case 130: if (isAlertOn) Alert(Symbol() + "-错误:无效的止损,止赢或挂单价离市价近.", " 定单号:" + ticket);break;
case 138: if (isAlertOn) Alert(Symbol() + "-错误:价格过期,交易失败.", " 定单号:" + ticket);break;
case 148: if (isAlertOn) Alert(Symbol() + "-错误:帐户定单过多,交易失败.", " 定单号:" + ticket);break;
default :
{
if (isAlertOn) Alert(Symbol() + "-错误:其它错误#", errCode, " 定单号:" + ticket);break;
}
break;
}
}
return (false);
}
好东东必须大家一起分享 谢谢楼主,共同发展 学习了,不错 帮你顶下哈!! 谢谢楼主分享 {:1_181:} {:1_186:} {:1_181:} 支持下
页:
[1]
2