并发开仓风险度怎么控制
大佬,请问多品种并发开仓,导致风险度打爆,应该怎么办,我现在用的是10秒钟K线,再小闪烁就多了代码部分:Params//参数Numeric maxRiskRatio(0.7); // 最大风险度阈值(70%),超过此值禁止开仓Vars//变量Numeric currentTotalMargin; // 用于本Bar累计计算保证金,解决同一根Bar多个信号并发问题Numeric riskRatio; // 当前账户风险度(保证金/权益)OnBar(ArrayRef<Integer> indexs)Numeric totalMargin = A_TotalMargin(); // 获取账户总持仓保证金Numeric currentEquity = A_CurrentEquity(); // 获取账户动态权益riskRatio = 0; // 默认风险度为0(回测模式允许开仓)If(currentEquity > 0) // 只有实盘连接时才计算真实风险度{ riskRatio = totalMargin / currentEquity; // 计算风险度 = 保证金 / 权益Commentary("【风控】风险度: " + text(riskRatio * 100) + "%"); // 输出风控信息If(riskRatio >= maxRiskRatio) // 如果风险度超限 { Commentary("【风控】 风险度超限 " + text(riskRatio * 100) + "% ≥ " + text(maxRiskRatio * 100) + "%"); // 输出警告} } Else // 回测模式下 { riskRatio = 0; //回测模式默认允许开仓Commentary("【风控】回测模式,风控已跳过"); // 输出提示} ===========新Bar重置累计保证金 =============================If(CurrentBar > 0) // 只要不是第一根Bar,每个Bar开始时重置{ currentTotalMargin = A_TotalMargin(); // 从账户重新读取保证金,重置累计值 } 平仓部分======================== If(MarketPosition==1) { Sell(0, Max(Open, myEntryPrice - gdzs * MinMove * PriceScale)); currentTotalMargin = A_TotalMargin();//平仓后重新从账户读取保证金}开仓部分======================== if(MarketPosition==0 //无持仓{ Numeric openPrice = max(open, highest_in_day); // 开仓价格 Numeric oneLotMargin = openPrice * ContractUnit * 0.10; // 估算开1手需要多少保证金(假设保证金率10%) Numeric currentEquity2 = A_CurrentEquity(); // 获取当前账户权益 Numeric afterRiskRatio = 1; // 默认禁止开仓 Bool canOpen = False; // 开仓标志If(currentEquity2 > 0) // 只有账户有效时才计算 { afterRiskRatio = (currentTotalMargin + oneLotMargin) / currentEquity2; // 计算开仓后风险度 } If(afterRiskRatio < maxRiskRatio) { canOpen = True; // 风控通过,允许开仓 } Else { Commentary("【风控】开多后风险度将达到 " + text(afterRiskRatio * 100) + "% ≥ " + text(maxRiskRatio * 100) + "% ,禁止开多!"); // 输出拒绝信息 } If(canOpen) // 只有风控通过才执行开仓 { buy(1, max(open, highest_in_day)); // 开多1手,成交价取开盘价和上轨价中的较大值(确保买入价不低于上轨) myEntryPrice = max(open, highest_in_day); //保存本次开仓价 trade_count = trade_count + 1; // 开仓次数加1 LastEntryBar = CurrentBar; // 记录本次开仓的K线索引currentTotalMargin = currentTotalMargin + oneLotMargin; //开仓成功后累加保证金,供本Bar下一个信号使用 commentary("突破上轨做多 | 开仓后风险度:" + text(afterRiskRatio * 100) + "%"); } }