以下策略有信号闪烁的情况,麻烦各位老师点拨一下
代码如下:
Params
Numeric P1(20);
Numeric P2(10000);
Vars
Series<Numeric> UpperBand;// 通道上轨
Series<Numeric> LowerBand;// 通道下轨
Series<Numeric> ATRVal;// ATRVal值
Numeric Lots(0);// 仓位
Events
OnReady()
{
}
OnBar(ArrayRef<Integer> indexs)
{
Numeric MinPoint = MinMove * PriceScale;// 最小变动价位
UpperBand = Highest(High[1],P1);
LowerBand = Lowest(Low[1],P1);
ATRVal = AvgTrueRange(14);
PlotNumeric("UpperBand", UpperBand);
PlotNumeric("LowerBand", LowerBand);
Lots = IntPart(P2/(ATRVal * 3 * ContractUnit() * BigPointValue()));
If(MarketPosition == 0)
{
// 开多
If(High > UpperBand)
{
Buy(Lots,UpperBand);
}
// 开空
If(Low < LowerBand)
{
SellShort(Lots,LowerBand);
}
}
If(MarketPosition > 0)
{
// 反转平多
If(Low < LowerBand)
{
Sell(0,LowerBand);
Commentary("多单反转平仓:"+Text(LowerBand));
}
}
If(MarketPosition < 0)
{
// 反转平空
If(High > UpperBand)
{
BuyToCover(0,UpperBand);
Commentary("空单反转平仓:"+Text(UpperBand));
}
}
}
ATRVal = AvgTrueRange(14);
回溯一个周期去使用
ATRVal [1]