非常不错的学习模板
input int tratp=300;//盈利多少点input int tp=150;//止损调高到盈利多少点
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
int total=OrdersTotal();
for(int i=0; i<total; i++)
{
if(OrderSelect(i, SELECT_BY_POS))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(OrderStopLoss()<OrderOpenPrice()+tp*Point && OrderClosePrice()-OrderOpenPrice()>tratp*Point)
{
bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+tp*Point, OrderTakeProfit(), 0);
}
}
if(OrderType()==OP_SELL)
{
if((OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-tp*Point) && OrderOpenPrice()-OrderClosePrice()>tratp*Point)
{
bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-tp*Point, OrderTakeProfit(), 0);
}
}
}
}
}
}
//+------------------------------------------------------------------+
页:
[1]