下面??是“智能交易?型”
//+------------------------------------------------------------------+
//| 自?止?.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2012, 惜墨"
#property link ""
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
extern double ??保?金比例=1;//是浮??以保?金,可根?杠杆和???修改
extern double 浮盈保?起始=0.5;//是浮盈?以保?金
extern double 浮盈保?比例=0.3;//是追?止?所保?的利??以保?金
extern double 初始止?=200;//是??,可根?平?和???修改
extern double 初始止盈=100;
extern double 允?滑?=20;
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
double 价格;
//自?爆?
if (AccountFreeMargin()==0)
{
for (int i=OrdersTotal();i>=0;i--)
{
if ( OrderSelect(i,SELECT_BY_POS)==true && OrderProfit()<0 && (OrderType()==OP_SELL || OrderType()==OP_BUY))
{
if (OrderType()==OP_BUY){价格=Bid;}else{价格=Ask;}
OrderClose(OrderTicket(),OrderLots(),价格,允?滑?);
}
}
}
for ( i=OrdersTotal();i>=0;i--)
{
if ( OrderSelect(i,SELECT_BY_POS)==true && (OrderType()==OP_SELL || OrderType()==OP_BUY))
{
//自?止?
double 保?金?用=100000/AccountLeverage()*OrderLots();
double 浮?盈?比 =MathAbs( OrderProfit()) / 保?金?用;
if (OrderType()==OP_BUY){价格=Bid;} else {价格=Ask;}
if ( OrderProfit()<0 && 浮?盈?比>??保?金比例)
OrderClose(OrderTicket(),OrderLots(),价格,允?滑?);
double 止?;
double 止盈;
//初始止?
if (OrderStopLoss()==0 && OrderSymbol()==Symbol())
{
if (OrderType()==OP_SELL){止?=OrderOpenPrice()+初始止?*Point;} else {止?=OrderOpenPrice()-初始止?*Point;}
if (OrderTakeProfit()!=0)
{ 止盈=OrderTakeProfit();}
else
{
if (OrderType()==OP_SELL){止盈=OrderOpenPrice()-初始止盈*Point;} else {止盈=OrderOpenPrice()+初始止盈*Point;}
}
Print ("止盈",止盈);
OrderModify(OrderTicket(),OrderOpenPrice(),止?,止盈,0);
}
//追?止?
if ( OrderProfit()>0 && 浮?盈?比>浮盈保?起始)
{
double dx;
dx=MathAbs((OrderOpenPrice()-价格))*浮盈保?比例;
if (浮?盈?比<1) {dx=MathAbs((OrderOpenPrice()-价格))*0.1;}
//Print ("浮?盈?比",浮?盈?比);
if (OrderType()==OP_SELL){止?=OrderOpenPrice()-dx;} else {止?=OrderOpenPrice()+dx;}
bool 允?修改=OrderStopLoss()==0;
if (OrderType()==OP_SELL){允?修改=允?修改 || 止?<OrderStopLoss();} else {允?修改=允?修改 || 止?>OrderStopLoss();}
//Print ("允?修改",允?修改);
//Print ("止?",止?);
if (允?修改)
OrderModify(OrderTicket(),OrderOpenPrice(),止?,OrderTakeProfit(),0);
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+ |