策略为什么没信号?

交易策略:开仓条件是:取每天上午9:00开盘后五分钟的高点和低点,向上突破高点做,每天只做一单(第一次突破),多单平仓条件是:持仓时间(变量1)1分钟,如果低于买入价则平仓,如果持仓时间超过1分钟且价格高于买入价,则(变量2)30分钟平仓。用在1分钟的K线上交易Params // 交易参数 Numeric TradeVolume(1); // 交易手数 Numeric PriceOffset(2); // 价格偏移点数 // 时间参数 (基于1分钟K线数量) Numeric RangeBars(5); // 区间计算Bar数 (9:00-9:05 = 5根1分钟K线) Numeric QuickExitBars(1); // 快速平仓Bar数 (1分钟) Numeric NormalExitBars(30); // 正常平仓Bar数 (30分钟)Vars // 基础变量 Numeric MinPoint; Bool RangeCalculated; Numeric DayHigh; Numeric DayLow; Bool TradeDoneToday; // Bar计数变量 Numeric DayBarCount; Numeric EntryBarCount; Numeric MyEntryPrice; // 信号变量 Bool BreakoutSignal; Bool FirstBarAfterRange;Events OnBar(ArrayRef<Integer> indexs) { // ========== 基础初始化 ========== MinPoint = MinMove * PriceScale; // ========== Bar计数管理 ========== DayBarCount = DayBarCount + 1; // ========== 新交易日检测 ========== If (Date != Date[1] Or DayBarCount > 240) // 240根Bar约为4小时交易 { RangeCalculated = False; TradeDoneToday = False; DayHigh = High; DayLow = Low; DayBarCount = 1; BreakoutSignal = False; FirstBarAfterRange = False; Commentary("========== 新交易日开始 =========="); Commentary("日期: " + Text(Date) + ", 初始Bar计数: " + Text(DayBarCount)); } // ========== 基于Bar计数的时间段判断 ========== Bool IsRangePeriod = (DayBarCount >= 1 And DayBarCount <= RangeBars); Bool IsTradingPeriod = (DayBarCount > RangeBars); // ========== 输出关键状态信息 ========== Commentary("Bar:" + Text(DayBarCount) + " 区间计算:" + IIFString(IsRangePeriod, "是", "否") + " 交易时段:" + IIFString(IsTradingPeriod, "是", "否") + " 开盘:" + Text(Open) + " 高:" + Text(High) + " 低:" + Text(Low) + " 收:" + Text(Close)); // ========== 区间计算逻辑 ========== If (IsRangePeriod And Not RangeCalculated) { // 初始化区间 If (DayBarCount == 1) { DayHigh = High; DayLow = Low; Commentary("初始化区间 - 高:" + Text(DayHigh) + " 低:" + Text(DayLow)); } Else { // 更新高点 If (High > DayHigh) { DayHigh = High; Commentary("更新高点: " + Text(DayHigh)); } // 更新低点 If (Low < DayLow) { DayLow = Low; Commentary("更新低点: " + Text(DayLow)); } } Commentary("当前区间 - 高:" + Text(DayHigh) + " 低:" + Text(DayLow)); } // ========== 区间确定 ========== If (DayBarCount == RangeBars + 1 And Not RangeCalculated) { RangeCalculated = True; FirstBarAfterRange = True; Commentary("========== 区间确定 =========="); Commentary("最终区间 - 高:" + Text(DayHigh) + " 低:" + Text(DayLow)); // 绘制区间线 PlotNumeric("DayHigh", DayHigh); PlotNumeric("DayLow", DayLow); PlotString("RangeInfo", "区间 " + Text(DayHigh) + "/" + Text(DayLow), High, Yellow); } Else { FirstBarAfterRange = False; } // ========== 突破检测和交易执行 ========== If (IsTradingPeriod And RangeCalculated And Not TradeDoneToday And MarketPosition == 0) { // 突破条件:收盘价突破区间高点 Bool BreakoutCondition = (Close > DayHigh); Commentary("突破检测 - 收盘:" + Text(Close) + " 区间高:" + Text(DayHigh) + " 突破:" + IIFString(BreakoutCondition, "是", "否")); If (BreakoutCondition) { BreakoutSignal = True; // 计算入场价格 Numeric EntryPrice = Close + MinPoint * PriceOffset; // 执行买入 Buy(TradeVolume, EntryPrice); // 记录交易信息 MyEntryPrice = EntryPrice; EntryBarCount = 0; TradeDoneToday = True; BreakoutSignal = False; Commentary("========== 执行多头入场 =========="); Commentary("入场价格: " + Text(EntryPrice)); Commentary("入场Bar: " + Text(DayBarCount)); PlotString("BuySignal", "BUY@" + Text(EntryPrice), Low, Red); } } // ========== 持仓Bar计数 ========== If (MarketPosition == 1 And BarsSinceEntry >= 0) { EntryBarCount = BarsSinceEntry; // 实时盈亏计算 Numeric CurrentProfit = (Close - MyEntryPrice) / MinPoint; Commentary("持仓状态 - Bar数:" + Text(EntryBarCount) + " 入场价:" + Text(MyEntryPrice) + " 当前价:" + Text(Close) + " 盈亏:" + Text(CurrentProfit) + "点"); } Else If (MarketPosition == 0) { EntryBarCount = 0; } // ========== 出场条件管理 ========== If (MarketPosition == 1 And BarsSinceEntry >= 0 And Vol > 0) { Bool ShouldExit = False; Numeric ExitPrice = 0; String ExitReason = ""; // 条件1: 持仓1分钟内(1根Bar)且价格低于买入价 - 快速止损 If (EntryBarCount <= QuickExitBars And Close < MyEntryPrice) { ShouldExit = True; ExitPrice = Close; ExitReason = "快速止损(1分钟内亏损)"; } // 条件2: 持仓超过1分钟且价格高于买入价,30分钟时平仓 - 定时止盈 Else If (EntryBarCount > QuickExitBars And Close > MyEntryPrice And EntryBarCount >= NormalExitBars) { ShouldExit = True; ExitPrice = Close; ExitReason = "定时止盈(30分钟)"; } // 条件3: 额外的保护止损 Else If (Close <= MyEntryPrice - 20 * MinPoint) // 20点止损 { ShouldExit = True; ExitPrice = Close; ExitReason = "保护止损"; } // 条件4: 尾盘平仓 (下午2:55之后) Else If (DayBarCount >= 235) // 假设9:00开始,235根Bar约为14:55 { ShouldExit = True; ExitPrice = Close; ExitReason = "尾盘平仓"; } // 执行平仓 If (ShouldExit) { Sell(0, ExitPrice); Commentary("========== 多头平仓 =========="); Commentary("平仓价格: " + Text(ExitPrice)); Commentary("持仓Bar数: " + Text(EntryBarCount)); Commentary("盈亏点数: " + Text((ExitPrice - MyEntryPrice) / MinPoint)); Commentary("平仓原因: " + ExitReason); PlotString("ExitSignal", "EXIT@" + Text(ExitPrice), High, Blue); } } // ========== 信号超时重置 ========== // 如果到上午11:00还没有交易,重置信号状态 If (DayBarCount >= 120 And Not TradeDoneToday And BreakoutSignal) // 120根Bar约为11:00 { BreakoutSignal = False; Commentary("========== 重置突破信号 =========="); Commentary("上午未触发交易,重置信号状态"); } // ========== 强制测试逻辑 ========== // 如果到第20根Bar还没有交易,进行强制测试 If (DayBarCount == 20 And Not TradeDoneToday And MarketPosition == 0 And RangeCalculated) { Commentary("========== 强制测试模式 =========="); Commentary("当前价格: " + Text(Close) + " 区间高: " + Text(DayHigh)); // 如果价格接近区间高点,强制突破 If (Close >= DayHigh - 10 * MinPoint) { Numeric TestEntryPrice = Close; Buy(TradeVolume, TestEntryPrice); MyEntryPrice = TestEntryPrice; EntryBarCount = 0; TradeDoneToday = True; Commentary("执行强制突破测试"); } } // ========== 状态监控输出 ========== // 在关键时点输出状态 Bool IsKeyBar = (FirstBarAfterRange Or BreakoutSignal Or MarketPosition != 0 Or Mod(DayBarCount, 30) == 0); // 每30根Bar输出一次 If (IsKeyBar) { Commentary("系统状态 - Bar:" + Text(DayBarCount) + " 区间状态:" + IIFString(RangeCalculated, "已计算", "未计算") + " 交易状态:" + IIFString(TradeDoneToday, "已交易", "未交易") + " 信号状态:" + IIFString(BreakoutSignal, "有信号", "无信号") + " 持仓:" + Text(MarketPosition) + " 区间高:" + Text(DayHigh)); } }帮我看一下以上策略为什么没有交易信号?

//------------------------------------------------------------------------// 简称: FiveMinBreakout_V2// 名称: 5分钟突破交易策略V2版本// 类别: 日内突破策略// 类型: 用户应用// 输出: Void//------------------------------------------------------------------------Params Numeric BreakoutMinutes(5); // 突破区间分钟数 Numeric HoldTimeLong(30); // 长期持仓时间(K线数) Numeric CloseTime(0.150000); // 收盘平仓时间 Numeric Lots(1); // 交易手数 Vars // 交易日管理变量 Series<Integer> CurrentDay(0); // 当前交易日 Series<Bool> NewDayFlag(False); // 新交易日标志 // 突破区间变量 Series<Numeric> MorningHigh(0); // 上午突破区间高点 Series<Numeric> MorningLow(0); // 上午突破区间低点 Series<Bool> RangeDefined(False); // 区间已定义标志 Series<Bool> TradeDone(False); // 当日已交易标志 Series<Integer> MorningBarsCount(0); // 上午K线计数 Series<Integer> TradeDirection(0); // 交易方向: 0-无, 1-多头, -1-空头 // 交易管理变量 Series<Numeric> EntryPrice(0); // 入场价格 Series<Integer> EntryBarIndex(0); // 入场Bar索引 Series<Integer> BarsSinceEntry(0); // 入场后经过的K线数 Series<Bool> PositionActive(False); // 仓位活跃标志 Numeric i; // 循环变量Events OnBar(ArrayRef<Integer> indexs) { // ====== 1. 交易日管理 ====== if (Date != CurrentDay) { // 新交易日重置所有标志 CurrentDay = Date; NewDayFlag = True; RangeDefined = False; TradeDone = False; PositionActive = False; MorningHigh = 0; MorningLow = 0; MorningBarsCount = 0; BarsSinceEntry = 0; TradeDirection = 0; Commentary("新交易日开始: " + Text(Date)); } else { NewDayFlag = False; } // ====== 2. 定义突破区间 ====== // 重置上午K线计数 if (Time < 0.090000) { MorningBarsCount = 0; } // 在9:00到9:00+BreakoutMinutes期间计算突破区间 Numeric BreakoutEndTime = 0.090000 + (BreakoutMinutes / 10000.0); if (Time >= 0.090000 && Time <= BreakoutEndTime && !RangeDefined) { MorningBarsCount = MorningBarsCount + 1; // 更新高低点 if (MorningBarsCount == 1) { // 第一根K线,初始化高低点 MorningHigh = High; MorningLow = Low; } else { // 后续K线,更新高低点 if (High > MorningHigh) MorningHigh = High; if (Low < MorningLow) MorningLow = Low; } Commentary("第" + Text(MorningBarsCount) + "根K线 - 高点:" + Text(MorningHigh) + " 低点:" + Text(MorningLow)); // 如果是最后一根K线,标记区间已定义 if (Time >= BreakoutEndTime || MorningBarsCount >= BreakoutMinutes) { RangeDefined = True; Commentary(Text(BreakoutMinutes) + "分钟区间定义完成 - 最终高点:" + Text(MorningHigh) + " 低点:" + Text(MorningLow)); } } // 突破区间结束后如果还没有定义区间,则标记为定义 if (Time > BreakoutEndTime && !RangeDefined && MorningHigh > 0) { RangeDefined = True; Commentary("区间定义完成(超时) - 高点:" + Text(MorningHigh) + " 低点:" + Text(MorningLow)); } // ====== 3. 交易信号生成 ====== if (Time > BreakoutEndTime && RangeDefined && !TradeDone && !PositionActive) { // 向上突破做多信号 - 只有当没有交易方向或当前是向上突破时 if (Close > MorningHigh && Vol > 0 && TradeDirection >= 0) { // 开多仓 Buy(Lots, Open); EntryPrice = Open; EntryBarIndex = CurrentBar; BarsSinceEntry = 0; TradeDone = True; PositionActive = True; TradeDirection = 1; // 标记为多头方向 Commentary("向上突破开多仓! 价格:" + Text(EntryPrice) + " 突破高点:" + Text(MorningHigh)); } // 向下突破做空信号 - 只有当没有交易方向或当前是向下突破时 else if (Close < MorningLow && Vol > 0 && TradeDirection <= 0) { // 开空仓 SellShort(Lots, Open); EntryPrice = Open; EntryBarIndex = CurrentBar; BarsSinceEntry = 0; TradeDone = True; PositionActive = True; TradeDirection = -1; // 标记为空头方向 Commentary("向下突破开空仓! 价格:" + Text(EntryPrice) + " 突破低点:" + Text(MorningLow)); } } // ====== 4. 更新持仓K线计数 ====== if (PositionActive) { BarsSinceEntry = CurrentBar - EntryBarIndex; } // ====== 5. 多头仓位管理 ====== if (MarketPosition == 1 && PositionActive) { // 条件1: 持仓K线数≥HoldTimeLong,平仓 if (BarsSinceEntry >= HoldTimeLong) { Sell(0, Close); // 使用收盘价平仓 PositionActive = False; Commentary("多单长期持仓平仓! 持仓K线数:" + Text(BarsSinceEntry)); } } // ====== 6. 空头仓位管理 ====== if (MarketPosition == -1 && PositionActive) { // 条件1: 持仓K线数≥HoldTimeLong,平仓 if (BarsSinceEntry >= HoldTimeLong) { BuyToCover(0, Close); // 使用收盘价平仓 PositionActive = False; Commentary("空单长期持仓平仓! 持仓K线数:" + Text(BarsSinceEntry)); } } // ====== 7. 收盘前平仓 ====== if (Time >= CloseTime && MarketPosition != 0) { if (MarketPosition == 1) { Sell(0, Open); Commentary("收盘前平多仓"); } else if (MarketPosition == -1) { BuyToCover(0, Open); Commentary("收盘前平空仓"); } PositionActive = False; TradeDone = True; } // ====== 8. 绘图和监控 ====== if (RangeDefined) { // 绘制突破区间 PlotNumeric("MorningHigh", MorningHigh); PlotNumeric("MorningLow", MorningLow); } if (PositionActive) { // 绘制入场价格线 PlotNumeric("EntryPrice", EntryPrice); PlotNumeric("BarsHeld", BarsSinceEntry); if (MarketPosition == 1) { Commentary("多单持仓中 - 入场价:" + Text(EntryPrice) + " 当前价:" + Text(Close) + " 持仓K线数:" + Text(BarsSinceEntry)); } else if (MarketPosition == -1) { Commentary("空单持仓中 - 入场价:" + Text(EntryPrice) + " 当前价:" + Text(Close) + " 持仓K线数:" + Text(BarsSinceEntry)); } } }

试试这个版本

//------------------------------------------------------------------------// 简称: FiveMinBreakout_V1// 名称: 5分钟突破交易策略V1版本// 类别: 日内突破策略// 类型: 用户应用// 输出: Void//------------------------------------------------------------------------Params Numeric HoldTimeShort(1); // 短期持仓时间(K线数) Numeric HoldTimeLong(30); // 长期持仓时间(K线数) Numeric Lots(1); // 交易手数 Vars // 交易日管理变量 Series<Integer> CurrentDay(0); // 当前交易日 Series<Bool> NewDayFlag(False); // 新交易日标志 // 突破区间变量 Series<Numeric> MorningHigh(0); // 上午9:00-9:05高点 Series<Numeric> MorningLow(0); // 上午9:00-9:05低点 Series<Bool> RangeDefined(False); // 区间已定义标志 Series<Bool> TradeDone(False); // 当日已交易标志 Series<Integer> MorningBarsCount(0); // 上午K线计数 // 交易管理变量 Series<Numeric> EntryPrice(0); // 入场价格 Series<Integer> EntryBarIndex(0); // 入场Bar索引 Series<Integer> BarsSinceEntry(0); // 入场后经过的K线数 Series<Bool> PositionActive(False); // 仓位活跃标志 Numeric i; // 循环变量Events OnBar(ArrayRef<Integer> indexs) { // ====== 1. 交易日管理 ====== if (Date != CurrentDay) { // 新交易日重置所有标志 CurrentDay = Date; NewDayFlag = True; RangeDefined = False; TradeDone = False; PositionActive = False; MorningHigh = 0; MorningLow = 0; MorningBarsCount = 0; BarsSinceEntry = 0; Commentary("新交易日开始: " + Text(Date)); } else { NewDayFlag = False; } // ====== 2. 定义突破区间 (9:00-9:05) ====== // 重置上午K线计数 if (Time < 0.090000) { MorningBarsCount = 0; } // 在9:00到9:05期间计算前5根K线 if (Time >= 0.090000 && Time <= 0.090500 && !RangeDefined) { MorningBarsCount = MorningBarsCount + 1; // 如果是前5根K线,更新高低点 if (MorningBarsCount <= 5) { if (MorningBarsCount == 1) { // 第一根K线,初始化高低点 MorningHigh = High; MorningLow = Low; } else { // 后续K线,更新高低点 if (High > MorningHigh) MorningHigh = High; if (Low < MorningLow) MorningLow = Low; } Commentary("第" + Text(MorningBarsCount) + "根K线 - 高点:" + Text(MorningHigh) + " 低点:" + Text(MorningLow)); // 如果是第5根K线,标记区间已定义 if (MorningBarsCount == 5) { RangeDefined = True; Commentary("5分钟区间定义完成 - 最终高点:" + Text(MorningHigh) + " 低点:" + Text(MorningLow)); } } } // 9:05后如果还没有定义区间,则标记为定义 if (Time > 0.090500 && !RangeDefined && MorningHigh > 0) { RangeDefined = True; Commentary("区间定义完成(超时) - 高点:" + Text(MorningHigh) + " 低点:" + Text(MorningLow)); } // ====== 3. 交易信号生成 (9:05之后) ====== if (Time > 0.090500 && RangeDefined && !TradeDone && !PositionActive) { // 向上突破做多信号 if (Close > MorningHigh && Vol > 0) { // 开多仓 Buy(Lots, Open); EntryPrice = Open; EntryBarIndex = CurrentBar; BarsSinceEntry = 0; TradeDone = True; PositionActive = True; Commentary("突破开多仓! 价格:" + Text(EntryPrice) + " 突破高点:" + Text(MorningHigh) + " 当前Bar:" + Text(CurrentBar)); } } // ====== 4. 更新持仓K线计数 ====== if (PositionActive) { BarsSinceEntry = CurrentBar - EntryBarIndex; } // ====== 5. 多头仓位管理 ====== if (MarketPosition == 1 && PositionActive) { // 条件1: 持仓K线数≤1且价格低于买入价则平仓 if (BarsSinceEntry <= HoldTimeShort && Low < EntryPrice) { Sell(0, Min(Open, EntryPrice)); PositionActive = False; Commentary("短期止损平仓! 持仓K线数:" + Text(BarsSinceEntry) + " 价格低于入场价"); } // 条件2: 持仓K线数≥30,在第30根K线收盘时平仓 else if (BarsSinceEntry >= HoldTimeLong) { Sell(0, Close); // 使用收盘价平仓 PositionActive = False; Commentary("长期止盈平仓! 持仓K线数:" + Text(BarsSinceEntry) + " 达到目标持仓K线数"); } // 条件3: 强制平仓 - 如果持仓K线数超过最大限制(35根) else if (BarsSinceEntry > HoldTimeLong + 5) { Sell(0, Open); PositionActive = False; Commentary("强制平仓! 持仓K线数:" + Text(BarsSinceEntry)); } } // ====== 6. 收盘前平仓 ====== if (Time >= 0.150000 && MarketPosition != 0) { if (MarketPosition == 1) { Sell(0, Open); Commentary("收盘前平仓"); } PositionActive = False; TradeDone = True; } // ====== 7. 绘图和监控 ====== if (RangeDefined) { // 绘制突破区间 PlotNumeric("MorningHigh", MorningHigh); PlotNumeric("MorningLow", MorningLow); } if (PositionActive) { // 绘制入场价格线 PlotNumeric("EntryPrice", EntryPrice); PlotNumeric("BarsHeld", BarsSinceEntry); Commentary("持仓中 - 入场价:" + Text(EntryPrice) + " 当前价:" + Text(Close) + " 持仓K线数:" + Text(BarsSinceEntry)); } }

既然一个信号都没有条件检查过吗?

AI写的吗你上面又是5分钟 ,1分钟 又是30分钟你加载在什么周期?

回复:1分钟周期