🏷 数学/数组 MathMax()/MathMin():优雅地写边界条件
小기능大用处:边界条件写法的整洁度对比。
【风控上限】double lot = MathMin(calcLot, MaxLot); 一行替代 if 判断。
【步长取整组合拳】
lot = MathMax(MinLot, MathMin(calcLot, MaxLot));
lot = MathFloor(lot / LotStep) * LotStep;
로트 수数永远落在 [MinLot, MaxLot] 且对齐步长——这三行是所有 EA 手数模块的标准形态。
【时段窗口】判断当前小时是否在交易窗口内:bool ok = dt.hour >= MathMin(h1, h2) && dt.hour <= MathMax(h1, h2);(顺手처리了 h1>h2 的跨零点参数失误)。
【止损距离】最小止损距离保护:slPoints = MathMax(slPoints, (double)SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL));
小기능连起来就是防御性编程的城墙。
【风控上限】double lot = MathMin(calcLot, MaxLot); 一行替代 if 判断。
【步长取整组合拳】
lot = MathMax(MinLot, MathMin(calcLot, MaxLot));
lot = MathFloor(lot / LotStep) * LotStep;
로트 수数永远落在 [MinLot, MaxLot] 且对齐步长——这三行是所有 EA 手数模块的标准形态。
【时段窗口】判断当前小时是否在交易窗口内:bool ok = dt.hour >= MathMin(h1, h2) && dt.hour <= MathMax(h1, h2);(顺手처리了 h1>h2 的跨零点参数失误)。
【止损距离】最小止损距离保护:slPoints = MathMax(slPoints, (double)SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL));
小기능连起来就是防御性编程的城墙。
🔥 이 사용자의 인기 게시글
🆕 이 사용자의 최신 게시글
답글(0)
아직 답글이 없습니다. 첫 댓글을 남겨보세요!