// 策略名称:多周期趋势动量策略
// 适用周期:5分钟/15分钟/30分钟/60分钟
// 交易品种:螺纹钢(RB)、铁矿石(I)、PTA(TA)、甲醇(MA)、豆粕(M)等<10个品种
// 参数设置
input:
FastLength(20), // 快速均线周期
SlowLength(50), // 慢速均线周期
ATRLength(14), // ATR周期
StopLossRatio(1.5), // 止损倍数
TakeProfitRatio(3), // 止盈倍数
TradeStartTime(0900), // 交易开始时间
TradeEndTime(1430); // 交易结束时间
// 变量声明
vars:
maFast(0), // 快速均线
maSlow(0), // 慢速均线
atrValue(0), // ATR值
trendDir(0), // 趋势方向
entryPrice(0), // 入场价格
stopLossPrice(0), // 止损价格
takeProfitPrice(0); // 止盈价格
// 计算指标
maFast = AverageFC(Close,FastLength);
maSlow = AverageFC(Close,SlowLength);
atrValue = AvgTrueRange(ATRLength);
trendDir = maFast > maSlow ? 1 : maFast < maSlow ? -1 : trendDir[1];
// 交易条件
condition1 = Time >= TradeStartTime and Time <= TradeEndTime; // 交易时段
condition2 = VolatilityRatio(Close,20) > 0.3; // 波动率过滤
condition3 = MomentumRanking(Close,5) > 70; // 动量排名
// 多周期共振判断
value1 = CallIndicator("MACD_15m",MACDLine); // 调用15分钟MACD
value2 = CallIndicator("MA_60m",MAValue); // 调用60分钟均线
// 交易逻辑
if condition1 and condition2 and condition3 then begin
// 多头信号
if trendDir > 0 and Close > maFast and
value1 > 0 and value2 > Ref(value2,-1) then begin
Buy(1,Open);
entryPrice = Open;
stopLossPrice = entryPrice - StopLossRatio*atrValue;
takeProfitPrice = entryPrice + TakeProfitRatio*atrValue;
end
// 空头信号
if trendDir < 0 and Close < maFast and
value1 < 0 and value2 < Ref(value2,-1) then begin
SellShort(1,Open);
entryPrice = Open;
stopLossPrice = entryPrice + StopLossRatio*atrValue;
takeProfitPrice = entryPrice - TakeProfitRatio*atrValue;
end
end
// 止损止盈
SetStopLoss(stopLossPrice);
SetProfitTarget(takeProfitPrice);
// 平仓规则
if Time >= TradeEndTime - 5 then begin
Sell(0,Close);
BuyToCover(0,Close);
end
因为这个不是tb的语法
能不能按照我这个思路用tb的语法完善一下
看置顶帖的策略代写服务,按照要求上传需求文档
蠢AI写的,没有用的。建议你还是自己学把。
能不能按照我这个要求给我写一个