新手,昨天刚买的简语言,没编程基础,求大神给个超短线策略,我一般是做白银短线,快进快出,以前手动,很多时候被套跑不出,谢谢!
// 沪铝日内短线策略(终极修正版)
// 适用品种:沪铝主力合约(AL),时间周期:5分钟/20分钟K线
Params // 注意:必须为小写 params!
Numeric FastLength(5); // 短期均线周期(5分钟K线)
Numeric SlowLength(20); // 长期均线周期(20分钟K线)
Numeric ATRLength(14); // ATR周期(14分钟K线)
Numeric RiskRatio(1); // 单笔风险比例(1%,如10万资金单笔亏1000元)
Numeric TrailingStop(2); // 追踪止损百分比(2%)
Numeric Lots(1); // 交易手数(根据资金调整)
Numeric Commission(3); // 手续费(沪铝约3元/手)
Vars
Series<Numeric> FastMA; // 快速均线(收盘价)
Series<Numeric> SlowMA; // 慢速均线(收盘价)
Series<Numeric> ATR; // 平均真实波幅(元/吨)
Numeric EntryPrice; // 入场价格
Numeric StopLossPrice; // 动态止损价
Numeric AccountEquity; // 账户权益
Numeric MaxPosition; // 最大可开仓手数
Events
OnBar(ArrayRef<Integer> indexs)
{
// 1. 计算基础指标
FastMA = AverageFC(Close, FastLength); // 5周期均线
SlowMA = AverageFC(Close, SlowLength); // 20周期均线
ATR = AvgTrueRange(ATRLength); // ATR(TB内置函数)
// 2. 风险控制:计算最大可开仓手数
AccountEquity = Portfolio_CurrentCapital(); // 获取账户权益
MaxPosition = IntPart(AccountEquity * RiskRatio / 100 / (1.5 * ATR * 5));
Lots = Min(Lots, MaxPosition);
If(Lots < 1) Lots = 1; // 至少1手
// 3. 入场信号:金叉做多
If(CrossOver(FastMA, SlowMA) && MarketPosition == 0)
{
EntryPrice = Open; // 开盘价入场
StopLossPrice = EntryPrice - 1.5 * ATR; // 动态止损
Buy(Lots, EntryPrice); // 开多仓
SetStopLoss(StopLossPrice); // 设置止损
SetProfitTarget(EntryPrice + 2 * ATR); // 设置止盈
}
// 死叉做空
Else If(CrossUnder(FastMA, SlowMA) && MarketPosition == 0)
{
EntryPrice = Open; // 开盘价入场
StopLossPrice = EntryPrice + 1.5 * ATR; // 动态止损
SellShort(Lots, EntryPrice); // 开空仓
SetStopLoss(StopLossPrice); // 设置止损
SetProfitTarget(EntryPrice - 2 * ATR); // 设置止盈
}
// 4. 追踪止损(盈利后回撤2%触发)
If(MarketPosition == 1) // 持有多仓
{
If(Close > EntryPrice * (1 + TrailingStop/100))
{
StopLossPrice = Close - 1.5 * ATR;
SetStopLoss(StopLossPrice);
}
}
Else If(MarketPosition == -1) // 持有空仓
{
If(Close < EntryPrice * (1 - TrailingStop/100))
{
StopLossPrice = Close + 1.5 * ATR;
SetStopLoss(StopLossPrice);
}
}
// 5. 手续费扣除(实盘启用,回测可注释)
// Commission(Commission, Commission); // 开平仓手续费
}
以上编码提示params变量没有定义怎么处理呢
这是AI生成的TBQuant3的代码?请去对应版面发帖,这不是简语言代码
给我带编一个好吗
发图贴出你的购买记录,核实一下
三个月的不是免费提供一个策略吗
不提供策略,可免费代编一个
公司只提供软件,策略要自己来研究,公司不提供策略