class 下单
{
public:
ENUM_ORDER_TYPE_FILLING 交易量指令(string 币种,ENUM_ORDER_TYPE_FILLING 指令类型) ;
int Buy(string symbol,double lots,int slpoint,int tppoint,string com,int magic)
{
MqlTradeRequest request= {};
MqlTradeResult result= {};
request.action=TRADE_ACTION_DEAL;
request.symbol=symbol;
request.type_filling=交易量指令(request.symbol,交易量指令类型);request.type=ORDER_TYPE_BUY;
request.volume=lots;
request.deviation=100;
request.price=SymbolInfoDouble(symbol,SYMBOL_ASK);
request.sl=SymbolInfoDouble(symbol,SYMBOL_ASK)-slpoint*Point();
request.tp=SymbolInfoDouble(symbol,SYMBOL_ASK)+tppoint*Point();
request.comment=com;
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError()); // 如果不能发送请求,输出错误代码
//--- 操作信息
PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
return(result.order);
}
};
ENUM_ORDER_TYPE_FILLING 下单类 :: 交易量指令(string 币种,ENUM_ORDER_TYPE_FILLING 指令类型)
{
// 获取现价单开仓的交易命令类型 ( 如果一个交易币种同时允许SYMBOL_FILLING_FOK和SYMBOL_FILLING_IOC成交指令,则交易命令类型为ORDER_FILLING_FOK )
if(SymbolInfoInteger(币种,SYMBOL_FILLING_MODE)==SYMBOL_FILLING_IOC)
指令类型=ORDER_FILLING_IOC;
if(SymbolInfoInteger(币种,SYMBOL_FILLING_MODE)==SYMBOL_FILLING_FOK)
指令类型=ORDER_FILLING_FOK;
return(指令类型);
}
一个简单的下单脚本,上周能用现在却报错。
2022.01.18 15:57:27.733 16下单脚本 (XAUUSD,H1) OrderSend error 4756
2022.01.18 16:02:32.943 16下单脚本 (XAUUSD,H1) retcode=10013 deal=0 order=0
2022.01.18 16:25:07.378 Trades '50766323': failed request buy 1 at 1.68320 sl: 1.68120 tp: 1.68520 [Invalid request]
class 下单
{
public:
int Buy(string symbol,double lots,int slpoint,int tppoint,string com,int magic)
{
MqlTradeRequest request= {};
MqlTradeResult result= {};
request.action=TRADE_ACTION_DEAL;
request.symbol=symbol;
request.type=ORDER_TYPE_BUY;
request.volume=lots;
request.deviation=100;
request.price=SymbolInfoDouble(symbol,SYMBOL_ASK);
request.sl=SymbolInfoDouble(symbol,SYMBOL_ASK)-slpoint*Point();
request.tp=SymbolInfoDouble(symbol,SYMBOL_ASK)+tppoint*Point();
request.comment=com;
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError()); // 如果不能发送请求,输出错误代码
//--- 操作信息
PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
return(result.order);
}
};