EA系列之:风控ea(源码)
2019-01-30 16:19:10 作者:wwbwwbwang 我也要发布信息
ea参数描述:
本ea可以将账户的单子自动止盈止损,平保,还有移动止损。是风控管理的利器。
附源码:
extern double 止损点数=0;//止损点数
extern double 止盈点数=0;//止盈点数微点
extern bool 是否启用平保=true;//保本开关
extern double 平保点数=150;//保本盈利的起始点数
extern bool 是否启用移动止损=true;//移动止损开关
extern double 移动止损启动点数=250;//
extern double 移动止损点数=200;//
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
iDisplayInfo("banquan1", "ea那些事", 0, 6, 18, 12, "微软雅黑", Yellow);
if(止损点数!=0) 修改止损();
if(止盈点数!=0) 修改止盈();
if(是否启用平保)平保();
if(是否启用移动止损)移动止损();
//----
return(0);
}
//+------------------------------------------------------------------+
void 移动止损()
{
for (int cnt=0;cnt<OrdersTotal();cnt++)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==true)
{
if (OrderSymbol()==Symbol())
{
if (OrderType()==OP_BUY)
{
if(OrderClosePrice()>=OrderOpenPrice()+移动止损启动点数*Point)
{
if (OrderClosePrice()-OrderStopLoss()>Point*移动止损点数||OrderStopLoss()==0)
{
bool chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()-Point*移动止损点数,OrderTakeProfit(),0,CLR_NONE);
if (chenggong)Print("单号:"+OrderTicket()+"移动止损成功");
if(chenggong==false)Print("单号:"+OrderTicket()+"移动止损失败:"+GetLastError());
}
}
}
if (OrderType()==OP_SELL)
{
if(OrderClosePrice()<=OrderOpenPrice()-移动止损启动点数*Point)
{
if (OrderStopLoss()-OrderClosePrice()>Point*移动止损点数||OrderStopLoss()==0)
chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()+Point*移动止损点数,OrderTakeProfit(),0,CLR_NONE);
if (chenggong)Print("单号:"+OrderTicket()+"移动止损成功");
if(chenggong==false)Print("单号:"+OrderTicket()+"移动止损失败:"+GetLastError());
}
}
}
}
}
}
void 平保()
{
int cnt, total;
total=OrdersTotal();
for(cnt=total-1;cnt>=0;cnt--)
{
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==true)
{
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderStopLoss()<OrderOpenPrice() && Bid-OrderOpenPrice()>平保点数*Point)
{
bool chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
if (chenggong)
{
Print("单号:"+OrderTicket()+"平保成功");
}
if(chenggong==false)
{
Print("单号:"+OrderTicket()+"平保失败:"+GetLastError());
}
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && (OrderStopLoss()>OrderOpenPrice()||OrderStopLoss()==0)&&OrderOpenPrice()-Ask>平保点数*Point)
{
chenggong=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
if (chenggong)
{
Print("单号:"+OrderTicket()+"平保成功");
}
if(chenggong==false)
{
Print("单号:"+OrderTicket()+"平保失败:"+GetLastError());
}
}
}
}
}
void iDisplayInfo(string LableName,string LableDoc,int Corner,int LableX,int LableY,int DocSize,string DocStyle,color DocColor)
{
if (Corner == -1) return(0);
ObjectCreate(LableName, OBJ_LABEL, 0, 0, 0); //建立标签对象
ObjectSetText(LableName, LableDoc, DocSize, DocStyle,DocColor); //定义对象属性
ObjectSet(LableName, OBJPROP_CORNER, Corner); //确定坐标原点0-左上角1-右上角2-左下角3-右下角-1-不显示
ObjectSet(LableName, OBJPROP_XDISTANCE, LableX); //定义横坐标单位像素
ObjectSet(LableName, OBJPROP_YDISTANCE, LableY); //定义纵坐标单位像素
}
void 修改止损()
{
int cnt, total;
total=OrdersTotal();
for(cnt=total-1;cnt>=0;cnt--)
{
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==true)
{
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&OrderStopLoss()==0)
{
bool chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-止损点数*Point,OrderTakeProfit(),0,Green);
if (chenggong)
{
Print("单号:"+OrderTicket()+"修改止损成功");
}
if(chenggong==false)
{
Print("单号:"+OrderTicket()+"修改止损失败:"+GetLastError());
}
}
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&OrderStopLoss()==0)
{
chenggong=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+止损点数*Point,OrderTakeProfit(),0,Green);
if (chenggong)
{
Print("单号:"+OrderTicket()+"修改止损成功");
}
if(chenggong==false)
{
Print("单号:"+OrderTicket()+"修改止损失败:"+GetLastError());
}
}
}
}
}
void 修改止盈()
{
int cnt, total;
total=OrdersTotal();
for(cnt=total-1;cnt>=0;cnt--)
{
if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==true)
{
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&OrderTakeProfit()==0)
{
bool chenggong= OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+止盈点数*Point,0,Green);
if (chenggong)
{
Print("单号:"+OrderTicket()+"修改止盈成功");
}
}
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&OrderTakeProfit()==0)
{
chenggong=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-止盈点数*Point,0,Green);
if (chenggong)
{
Print("单号:"+OrderTicket()+"修改止盈成功");
}
}
}
}
}
联系我时,请说明是在“外汇联盟”上看到的,谢谢!
作者信息 | wwbwwbwang 【发送站内信息】 |
联系邮箱 | |
其他联系方式 | |
风险提示:分类信息皆由全球网友自行发布,本站无法核实相关信息的真实性,请审慎甄别,谨防上当受骗。投资有风险,入市需谨慎;过往业绩不代表未来表现;没有任何人可以保证收益。 |