你好帮我看一下代码.
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
MqlTradeResult result={};
MqlTradeRequest request={};
request.action=TRADE_ACTION_DEAL;
request.symbol=Symbol();
request.type=ORDER_TYPE_BUY;
request.volume=0.1;
request.deviation=100;
request.price=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
//request.sl=SymbolInfoDouble(Symbol(),SYMBOL_ASK)-200*Point();
//request.tp=SymbolInfoDouble(Symbol(),SYMBOL_ASK)+200*Point();
request.type_filling=ORDER_FILLING_IOC;
request.comment="com";
request.magic=223;
OrderSend(request,result);
//--- 发送请求
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError()); // 如果不能发送请求,输出错误代码
//--- 操作信息
PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
}
点一下,自动下了2个一模一样的单子.
OrderSend(request,result);
if(!OrderSend(request,result))
这两行重复下单!第一行是直接下单没有检测服务器返回代码,第二行是检测没有下单成功时服务器返回的代码。使用OrderSend发送订单成功并不代表开仓成功,所以要删掉第一行,保留第二行,这样下单失败时,可以在日志里查阅下单失败的原因,祝你好运!
你好帮我看一下代码.
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
MqlTradeResult result={};
MqlTradeRequest request={};
request.action=TRADE_ACTION_DEAL;
request.symbol=Symbol();
request.type=ORDER_TYPE_BUY;
request.volume=0.1;
request.deviation=100;
request.price=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
//request.sl=SymbolInfoDouble(Symbol(),SYMBOL_ASK)-200*Point();
//request.tp=SymbolInfoDouble(Symbol(),SYMBOL_ASK)+200*Point();
request.type_filling=ORDER_FILLING_IOC;
request.comment="com";
request.magic=223;
OrderSend(request,result);
//--- 发送请求
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError()); // 如果不能发送请求,输出错误代码
//--- 操作信息
PrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
}
点一下,自动下了2个一模一样的单子.