仓位出现盈利但又未达到目标,EA如何设置保本策略?
找到了没有楼主 |
|
|
|
|
void OnTick()
{
yidong();//当盈利100点的时候,启动保本1个点,当盈利200点的时候启动移动止损200点
}
void yidong()
{
for(int i=0;i<OrdersTotal();i++)//移动止损通用代码,次代码会自动检测buy和sell单并对其移动止损
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderType()==0 && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
if(ydd>0 && (Bid-OrderOpenPrice()) >=Point*ydd)
{
if(OrderStopLoss()<(Bid-Point*ydd) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*ydd,OrderTakeProfit(),0,Green);
}
}
if((Bid-OrderOpenPrice()) >=Point*yll)
{
if(OrderStopLoss()<(Bid+Point*1) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*1,OrderTakeProfit(),0,Green);
}
}
}
if(OrderType()==1 && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
if(ydd>0 && (OrderOpenPrice()-Ask)>=(Point*ydd))
{
if((OrderStopLoss()>(Ask+Point*ydd)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*ydd,OrderTakeProfit(),0,Red);
}
}
if((OrderOpenPrice()-Ask)>=(Point*yll))
{
if((OrderStopLoss()>(Ask-Point*1)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*1,OrderTakeProfit(),0,Red);
}
}
}
}
}
} |
|
|
|
|