一个错误,一个警告
MT5脚本,
单子如果盈利了,但是没有设置止损,双击一下脚本,把止损自动设置在入场价位处,也就是拉平保。
//+------------------------------------------------------------------+
//| 简化版盈亏平衡止损脚本 |
//+------------------------------------------------------------------+
void OnStart()
{
for(int i = PositionsTotal()-1; i>=0; i--)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
double openPrice = PositionGetDouble(POSITION_PRICE_OPEN);
double currentSL = PositionGetDouble(POSITION_SL);
// 如果当前有盈利且止损未设在入场价
if(PositionGetDouble(POSITION_PROFIT) > 0 && currentSL != openPrice)
{
MqlTradeRequest request = {0};
MqlTradeResult result = {0};
request.action = TRADE_ACTION_SLTP;
request.position = ticket;
request.sl = openPrice;
request.tp = PositionGetDouble(POSITION_TP);
OrderSend(request, result);
}
}
}
Print("盈亏平衡检查完成");
}
//+------------------------------------------------------------------+
现在chatgpt已经很智能了
韬客社区www.talkfx.co











