📢 AnúnciosGuia para iniciantes: tópicos, pontos e regras da comunidadeMT4/MT5 免安装包(Windows+安卓 APK)Baixar grátis(0 Pontos)Noções básicas: como ganhar pontos e atividade
Comunidade › Funções › MathMax()/MathMin():优雅地写边界条件

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

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

Respostas(0)

Ainda não há respostas — pegue o sofá!