请用MQL5代码按以上要求写一个修改止盈点,止损点的函数,不要调用库
时间: 2024-02-24 19:54:32 浏览: 31
好的,以下是根据你提供的要求写的一个修改止盈止损点的函数:
```C++
void modifyStopLossTakeProfit(double stopLoss, double takeProfit) {
double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
int ticket = OrderTicket();
if(ticket>0) {
double openPrice = OrderOpenPrice();
if (openPrice == 0) {
return;
}
int type = OrderType();
if (type == OP_BUY) {
if(currentPrice >= takeProfit) {
takeProfit += 100;
if(!OrderModify(ticket, openPrice, stopLoss, takeProfit, 0)) {
Print("Error modifying order ", ticket, " with SL=", stopLoss, " and TP=", takeProfit);
}
}
else if(currentPrice >= stopLoss) {
stopLoss -= 100;
if(!OrderModify(ticket, openPrice, stopLoss, takeProfit, 0)) {
Print("Error modifying order ", ticket, " with SL=", stopLoss, " and TP=", takeProfit);
}
}
}
else if (type == OP_SELL) {
if(currentPrice <= takeProfit) {
takeProfit -= 100;
if(!OrderModify(ticket, openPrice, stopLoss, takeProfit, 0)) {
Print("Error modifying order ", ticket, " with SL=", stopLoss, " and TP=", takeProfit);
}
}
else if(currentPrice <= stopLoss) {
stopLoss += 100;
if(!OrderModify(ticket, openPrice, stopLoss, takeProfit, 0)) {
Print("Error modifying order ", ticket, " with SL=", stopLoss, " and TP=", takeProfit);
}
}
}
}
}
```
这个函数接受两个参数,即止损点和止盈点。它首先获取当前价格和订单编号,然后检查订单是否为买单或卖单。如果市价大于等于设定的止盈点,就修改止盈点为设定的止盈点加上100毫点。如果市价大于等于设定的止损点,就修改止损点为设定的止损点减去100毫点。如果修改失败,函数会输出错误信息。