【发布时间】:2020-08-21 03:26:51
【问题描述】:
以下是我在三分钟后未通过时下单的方法。我已经将它的大部分从 mql4 转换为 mql5。这只是注释部分,我不确定我将如何更改为 mql5,因为在 mql5 中发送订单返回 bool 而非 int。如果我能得到帮助来修复剩下的部分,我会很高兴。
void MakeOrders()
{
static datetime lastTime = 0;
datetime currTime = iTime(Symbol(),PERIOD_M3,0);
if (currTime>lastTime)
{
for (int i=ObjectsTotal(0, 0, -1)-1; i>=0; i--)
{
string name = ObjectName(0, i, 0, -1);
if (ObjectGetString(0, name, OBJPROP_NAME, 0)==OBJ_RECTANGLE && ObjectGetString(0,name,OBJPROP_TEXT)=="")
{
double entryPrice=ObjectGetDouble(0,name,OBJPROP_PRICE,1)-3*_Point;
double stopLoss=ObjectGetDouble(0,name,OBJPROP_PRICE,2);
double slDist=fabs(entryPrice-stopLoss);
double dTakeProfit=entryPrice-2*slDist;
MqlTradeRequest request={0};
MqlTradeResult result={0};
//--- parameters of request
request.action =TRADE_ACTION_DEAL; // type of trade operation
request.symbol =Symbol(); // symbol
request.volume =lotSize; // volume of 0.1 lot
request.type =ORDER_TYPE_BUY_LIMIT; // order type
request.price = entryPrice; // price for opening
//request.deviation=5; // allowed deviation from the price
request.magic =magicnumber; // MagicNumber of the order
request.tp = dTakeProfit;
request.sl = stopLoss;
//--- send the request
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError());
/*
int ticketSell = OrderSend(Symbol(),OP_SELLLIMIT,lotSize, entryPrice,0,stopLoss,dTakeProfit,"SellOrder",magicnumber,0,Red);
if (ticketSell>0)
{
ObjectSetText(name,string(ticketSell));
i = ObjectsTotal()-1; // rather than continuing the 'for' loop, we must restart because arrows (ie new objects) were created.
}
*/
}
}
lastTime = currTime;
}
}
【问题讨论】:
-
发送
OrderSend()接受请求和结果,并检查结果。 -
@DanielKniaz 我添加了
OrderSend(request,result);,但什么也没发生。所以我向if (ObjectGetString(0, name, OBJPROP_NAME, 0)==OBJ_RECTANGLE && ObjectGetString(0,name,OBJPROP_TEXT)==""){}添加了一个打印语句,它没有打印。此条件的原始 mql4 代码是if (ObjectType(name)==OBJ_RECTANGLE && ObjectDescription(name)=="") {}。也许我没有很好地转换那一点。不确定。 -
@DanielKniaz 我无法解决这个问题
标签: mql4 algorithmic-trading mql5 mt4 metatrader5