📢 Mga AnunsyoGabay sa baguhan: pag-post, puntos, at patakaran ng komunidadMT4/MT5 免安装包(Windows+安卓 APK)libreng pag-download(0 Points)Mga batayan: paano kumita ng puntos at aktibidad
Komunidad › Function › MathMax()/MathMin():优雅地写边界条件

🏷 数学/数组 MathMax()/MathMin():优雅地写边界条件

admin Beterano AA · 2026-12-02 10:29 · Mga View 52 · mga reply 0
小Function大用处:边界条件写法的整洁度对比。
【风控上限】double lot = MathMin(calcLot, MaxLot); 一行替代 if 判断。
【步长取整组合拳】
lot = MathMax(MinLot, MathMin(calcLot, MaxLot));
lot = MathFloor(lot / LotStep) * LotStep;
Lots数永远落在 [MinLot, MaxLot] 且对齐步长——这三行是所有 EA 手数模块的标准形态。
【时段窗口】判断当前小时是否在交易窗口内:bool ok = dt.hour >= MathMin(h1, h2) && dt.hour <= MathMax(h1, h2);(顺手Pangasiwaan了 h1>h2 的跨零点参数失误)。
【止损距离】最小止损距离保护:slPoints = MathMax(slPoints, (double)SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL));
小Function连起来就是防御性编程的城墙。
← iCustom():调用自定义Indicator的万能 OrderModify():Move止损与保 →

Mga Reply(0)

Wala pang reply — unahan mo!