有您的持续关注
我们会做得更好

EA平仓函数模块的又一表达方式



平仓函数模块的又一表达方式
bool CloseOrder(int Ticket, double Lots, int myOrderType,string myOrderSymbol)
{
bool res;
int ErrorCode;
double Price;
bool Status = false;
if(myOrderType == OP_BUYLIMIT || myOrderType == OP_BUYSTOP ||
myOrderType == OP_SELLLIMIT || myOrderType == OP_SELLSTOP)
{
OrderDelete(OrderTicket());
return(true);
}
if (myOrderType == OP_BUY) Price = MarketInfo(myOrderSymbol,MODE_BID);
if (myOrderType == OP_SELL) Price = MarketInfo(myOrderSymbol,MODE_ASK);
if (MarketInfo(myOrderSymbol,MODE_DIGITS) > 0)
Price = NormalizeDouble(Price, MarketInfo(myOrderSymbol,MODE_DIGITS));
int cnt = 0;
while (!Status) {
if (IsTradeAllowed() == true) {
res = OrderClose(Ticket, Lots, Price, MarketInfo(myOrderSymbol,MODE_SPREAD),
Violet);
ErrorCode = GetLastError();
} else cnt++;
if (res == true) Status = true;
ErrorCode = GetLastError();
switch (ErrorCode) {
case 0/* NO_ERROR */:
Status = true;
break;
case 4/* SERVER_BUSY */:
case 6/* NO_CONNECTION */:
case 129/* INVALID_PRICE */:
case 136/* OFF_QUOTES */:
case 137/* BROKER_BUSY */:
case 146/* TRADE_CONTEXT_BUSY */:
case 128/* TRADE_TIMEOUT */:
RefreshRates();
cnt++;
break;
case 135/* PRICE_CHANGED */:
case 138/* REQUOTE */:
RefreshRates();
continue;
default:
Status = TRUE;
}
if (cnt > 20) Status = TRUE; //10 time try
if (!Status)
{
Sleep(500);
RefreshRates();
}
}
if (res == true || ErrorCode == 0/* NO_ERROR */) return (true);
Print(” Error closing order : (“, ErrorCode, “) ” + ErrorDescription(ErrorCode));
return (false);
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » EA平仓函数模块的又一表达方式
上一篇:
下一篇:
分享到:更多 ()