有找人写过一段,但是控制不住日内交易次数
Params Numeric FastLength(5); // 快速均线周期 Numeric SlowLength(20); // 慢速均线周期 Numeric ExitTime1(1455); // 平仓时间(如14:55)Vars Series<Numeric> FastMA; // 快速均线 Series<Numeric> SlowMA; // 慢速均线 Numeric TradeCount(0); // 当日交易次数 Bool isEnterCondition; // 是否满足入场条件// 均线计算Events OnBar(ArrayRef<Integer> indexs) { FastMA = XAverage(Close, FastLength); SlowMA = XAverage(Close, SlowLength); // 判断是否为新一天,重置交易次数 If(Date != Date[1]) TradeCount = 0; // 入场条件:金叉 isEnterCondition = CrossOver(FastMA, SlowMA); // 开仓逻辑:金叉 + 当前无持仓 + 交易次数 < 10 If(isEnterCondition && TradeCount < 10 && MarketPosition == 0) { Buy(1, Open); TradeCount = TradeCount + 1; } // 收盘前统一平仓 If(Time >= ExitTime1 && MarketPosition != 0) Sell(0, Open); }