/*
算法如下:
1、检测所下单子(不包括挂单,不检查货币对),若单子未设置止损和止盈,则根据默认输入参数设置止损和止盈。
2、若单子发生盈利,并达到移动止损触发线,则动态提高原有止损线,进入移动止损状态。
3、当盈利大于移动止损值的10倍时,移动止损的值为总盈利的1/10。
函数参数如下:
double g_initstop; //初始止损
double g_initprofit; //初始止盈
double g_linestop; //移动止损触发线
double g_yd; //移动止损值
void comment; //不是此标识的不处理,0表示关闭这个判断
*/
//+------------------------------------------------------------------+
#property copyright "Dagan"
#property link ""
#include
/*
double g_initstop; //初始止损
double g_initprofit; //初始止盈
double g_linestop; //移动止损触发线
double g_yd; //移动止损值
void comment; //不是此标识的不处理,0表示关闭这个判断
*/
int ydstop(double g_initstop,double g_initprofit,double g_linestop,double g_yd,string comment)
{
int total=OrdersTotal(); //所有单量
for(int i=0;i=g_linestop && realProfit=g_linestop && realProfit>g_yd*10)
{
takeProfit=price+4*flag*g_yd*Point;
stopLoss=price-flag*0.1*realProfit*Point;
}
takeProfit=NormalizeDouble(takeProfit,Digits);
stopLoss=NormalizeDouble(stopLoss,Digits);
/*----------------------------------------
2、若单子发生盈利,并达到移动止损触发线,则动态提高原有止损线,进入移动止损状态。
3、当盈利大于移动止损值的10倍时,移动止损的值为总盈利的1/10。
end
----------------------------------------*/
//止损止赢下达操作
//Print("b"+takeProfit);
//Print("c"+OrderStopLoss());
if((flag==1 && (stopLoss>OrderStopLoss() || takeProfit>OrderTakeProfit())) ||
(flag==-1 && (stopLoss<OrderStopLoss() || takeProfit<OrderTakeProfit())) ||
OrderStopLoss()==0 || OrderTakeProfit()==0
)
{
RefreshRates();
Print("w_order before modify: tk("+OrderTicket()+"), sl("+DoubleToStr(OrderStopLoss(),Digits)+"), tp("+DoubleToStr(OrderTakeProfit(),Digits)+"),stopLoss:"+stopLoss+",takeProfit:"+takeProfit);
OrderModify(OrderTicket(),OrderOpenPrice(),stopLoss,takeProfit,0);
w_error ();
}
}
}
return(0);
}
//--------------以下为函数--------------------------
double w_error ()
{
int error=GetLastError();
if (error!=0)
{
if (!(error == 4/* SERVER_BUSY */ || error == 137/* BROKER_BUSY */ || error == 146/* TRADE_CONTEXT_BUSY */ || error == 136/* OFF_QUOTES */)) Print("w_ticket_ErrorCode = "+error+",Description = "+ErrorDescription(error));
else
{
Print("w_ticket_ErrorCode = "+error+",Description = "+ErrorDescription(error));
Sleep(1000);
}
}
return(error);
}
|