//------------------------------------------------------------------------
// 简称: BollingerBreakout
// 名称: 布林通道突破策略
// 类别: 公式应用
// 类型: 内建应用
//------------------------------------------------------------------------
Params
Numeric BBLen(20); // 布林通道周期
Numeric BWidth(2); // 布林通道宽度
Numeric StopLossPercent(5); // 本金回撤止损百分比
Numeric VolumeFilterMultiplier(10); // 成交量过滤倍数
Numeric PriceDropRatio(1.236); // 价格跌幅比例
Numeric BollingerDropRatio(0.1236); // 布林通道下轨跌幅比例
Vars
Numeric MinPoint; // 最小变动单位
Series<Numeric> MidLine; // 布林通道中轨
Series<Numeric> UpperBand; // 布林通道上轨
Series<Numeric> LowerBand; // 布林通道下轨
Series<Numeric> AvgVolume; // 前30根K线最低五个K线成交量均量
Series<Numeric> PreClose; // 昨日收盘价
Series<Numeric> PreLowerBand; // 30个K线前的布林通道下轨
Numeric EntryPrice; // 开仓价格
Numeric StopLossPrice; // 本金回撤止损价
Bool BuyCondition(False); // 买入条件
Events
OnBar(ArrayRef<Integer> indexs)
{
// 初始化
MinPoint = MinMove * PriceScale;
// 计算布林通道
MidLine = Average(Close, BBLen);
UpperBand = MidLine + BWidth * StandardDev(Close, BBLen, 2);
LowerBand = MidLine - BWidth * StandardDev(Close, BBLen, 2);
// 计算前30根K线最低五个K线成交量均量
AvgVolume = Average(Lowest(Volume, 30), 5);
// 计算昨日收盘价
PreClose = Close[1];
// 计算30个K线前的布林通道下轨
PreLowerBand = LowerBand[30];
// 绘制布林通道
PlotNumeric("MidLine", MidLine);
PlotNumeric("UpperBand", UpperBand);
PlotNumeric("LowerBand", LowerBand);
// 买入条件
BuyCondition = (
(Low / PreClose - 1) * 100 < PriceDropRatio && // 最低价跌幅小于1.236%
Low < LowerBand && // 最低价低于布林通道下轨
Volume > AvgVolume * VolumeFilterMultiplier && // 成交量是前30根K线最低五个K线成交量均量的10倍
LowerBand < PreLowerBand * (1 - BollingerDropRatio / 100) // 当前布林通道下轨价格低于30个K线前的0.1236%
);
// 开仓逻辑
If(MarketPosition == 0 && BuyCondition)
{
EntryPrice = Open; // 以开盘价开仓
Buy(1, EntryPrice);
// 计算止损价
StopLossPrice = EntryPrice * (1 - StopLossPercent / 100); // 本金回撤5%止损
}
// 止损逻辑
If(MarketPosition == 1)
{
// 本金回撤5%止损
If(Low <= StopLossPrice)
{
Sell(0, StopLossPrice);
}
}
}
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08
// 版权所有 TradeBlazer Software 2003-2025
// 更改声明 TradeBlazer Software保留对TradeBlazer平
// 台每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
提示
你为什么会不定义呢
要编译通过的话,加一句
Series<Numeric> volume;
谢谢大神