// 策略名称:TB Quant 日内多空策略(严格合规版)
Strategy("TB_Intraday_Strategy", "1.0");
// 输入参数
Input:
BreakPoint(14), // 突破点数(14点)
StopLossPoint(15), // 止损点数(15点)
StopOpenTime(143000), // 停止开仓时间(14:30:00,HHMMSS格式)
CloseTime(145955); // 尾盘清仓时间(14:59:55)
// 变量声明
Var:
TodayLow(0), // 当日最低价(1分钟周期)
TodayHigh(0), // 当日最高价(1分钟周期)
LongEntry(0), // 多头开仓触发价
ShortEntry(0), // 空头开仓触发价
LongStop(0), // 多头止损价
ShortStop(0), // 空头止损价
CurrentTime(0), // 当前时间(HHMMSS格式)
LongTrades(0), // 当日多头开仓次数
ShortTrades(0), // 当日空头开仓次数
LastTradeDay(0); // 上次交易日标记
// 主逻辑入口
Begin
// 每日初始化:新交易日重置开仓次数
If CurrentDate <> LastTradeDay Then
LongTrades = 0;
ShortTrades = 0;
LastTradeDay = CurrentDate;
End If;
// 计算当日高低点(1分钟周期,仅统计当日数据)
TodayLow = Lowest(Low, BarsSinceSession + 1, True);
TodayHigh = Highest(High, BarsSinceSession + 1, True);
// 计算开仓触发价
LongEntry = TodayLow + BreakPoint;
ShortEntry = TodayHigh - BreakPoint;
// 记录开仓止损价(开仓后立即计算)
If MarketPosition = 1 And BarsSinceEntry = 1 Then
LongStop = EntryPrice - StopLossPoint;
End If;
If MarketPosition = -1 And BarsSinceEntry = 1 Then
ShortStop = EntryPrice + StopLossPoint;
End If;
// 时间转换(HHMMSS格式)
CurrentTime = Hour * 10000 + Minute * 100 + Second;
// 多头开仓条件:未开多 + 价格触发 + 14:30前
If LongTrades = 0 And Close >= LongEntry And CurrentTime < StopOpenTime Then
Buy(1, LongEntry); // 指令价开仓
LongTrades = 1;
End If;
// 空头开仓条件:未开空 + 价格触发 + 14:30前
If ShortTrades = 0 And Close <= ShortEntry And CurrentTime < StopOpenTime Then
SellShort(1, ShortEntry); // 指令价开仓
ShortTrades = 1;
End If;
// 多头止损(市价平仓)
If MarketPosition = 1 And Close <= LongStop Then
Sell(0, 0);
End If;
// 空头止损(市价平仓)
If MarketPosition = -1 And Close >= ShortStop Then
BuyToCover(0, 0);
End If;
// 尾盘清仓(市价平仓)
If CurrentTime >= CloseTime Then
If MarketPosition = 1 Then
Sell(0, 0);
Else If MarketPosition = -1 Then
BuyToCover(0, 0);
End If;
End If;
End
AI浓度95%
这是你自己写的吗?
从第一句错到最后一句 不是tb语言