帮忙看下这个策略
虽然用的通道上下轨是【1】,但是他用high和low比较完直接用open作为入场价不太对吧?
应该直接用close还是high[1] low[1]来比较?
十分感谢
//------------------------------------------------------------------------
// 简称: DonchianBreakout
// 名称: 唐奇安通道突破系统(双向)
// 类别: 策略应用
// 类型: 内建应用
// 输出:
// 策略说明:
// 价格突破上轨开多,突破下轨开空;反向突破出场或跟踪止损
//------------------------------------------------------------------------
Params
Numeric EntryLen(20); // 入场通道周期
Numeric ExitLen(10); // 出场通道周期
Numeric ATRLen(10); // 波动率周期(用于止损)
Numeric StopMult(2); // 止损倍数(乘以ATR)
Numeric Lots(0); // 交易手数
Vars
Series<Numeric> UpperBand; // 入场上轨
Series<Numeric> LowerBand; // 入场下轨
Series<Numeric> ExitUpper; // 出场止损上轨(用于空头)
Series<Numeric> ExitLower; // 出场止损下轨(用于多头)
Series<Numeric> ATR; // 平均真实波幅
Series<Numeric> LongStop; // 多单动态止损价
Series<Numeric> ShortStop; // 空单动态止损价
Numeric MinPoint; // 最小变动价位
Events
OnBar(ArrayRef<Integer> indexs)
{
MinPoint = MinMove * PriceScale;
UpperBand = HighestFC(High[1], EntryLen); // 上一周期的N周期高点
LowerBand = LowestFC(Low[1], EntryLen); // 上一周期的N周期低点
ExitUpper = HighestFC(High[1], ExitLen); // 出场通道上轨
ExitLower = LowestFC(Low[1], ExitLen); // 出场通道下轨
ATR = AvgTrueRange(ATRLen);
PlotNumeric("UpperBand", UpperBand);
PlotNumeric("LowerBand", LowerBand);
// 多头开仓信号:价格突破上轨
If(High >= UpperBand + MinPoint And Vol > 0)
{
// 若持有空仓,先平空
If(MarketPosition == -1)
BuyToCover(0, Open);
// 开多
If(MarketPosition != 1)
{
Buy(Lots, Max(Open, UpperBand + MinPoint));
LongStop = EntryPrice - StopMult * ATR; // 初始止损
}
}
// 空头开仓信号:价格突破下轨
If(Low <= LowerBand - MinPoint And Vol > 0)
{
// 若持有多仓,先平多
If(MarketPosition == 1)
Sell(0, Open);
// 开空
If(MarketPosition != -1)
{
SellShort(Lots, Min(Open, LowerBand - MinPoint));
ShortStop = EntryPrice + StopMult * ATR; // 初始止损
}
}
// 更新多单止损(跟踪止损:以最近ExitLower为基础)
If(MarketPosition == 1 And BarsSinceEntry > 0)
{
LongStop = Max(LongStop[1], ExitLower - StopMult * ATR);
}
// 更新空单止损(跟踪止损:以最近ExitUpper为基础)
If(MarketPosition == -1 And BarsSinceEntry > 0)
{
ShortStop = Min(ShortStop[1], ExitUpper + StopMult * ATR);
}
// 多头出场:价格跌破止损价 或 突破下轨(反向信号)
If(MarketPosition == 1 And BarsSinceEntry > 0 And Vol > 0)
{
If(Low <= LongStop Or Low <= LowerBand - MinPoint)
{
Sell(0, Min(Open, Min(LongStop, LowerBand - MinPoint)));
}
}
// 空头出场:价格突破止损价 或 突破上轨(反向信号)
If(MarketPosition == -1 And BarsSinceEntry > 0 And Vol > 0)
{
If(High >= ShortStop Or High >= UpperBand + MinPoint)
{
BuyToCover(0, Max(Open, Max(ShortStop, UpperBand + MinPoint)));
}
}
}
//------------------------------------------------------------------------
模型如果出问题,谁写的问谁。