回测的时候出现程序体不存在,没找到原因,请帮忙下
Params
Numeric ATRs(9); // 几倍ATR止盈
Numeric ATRLength(18); // ATR周期
Integer Lots(1); //固定手数
Integer LotsMode(3); //头寸计算方式,1,固定手数,2固定值3资金比例
Numeric fixedmoney(100000); //固定市值
Numeric moneyrate(0.7); //资金比例70%
Vars
Series<Numeric> WAvgPrice; // K线加权均值
Series<Numeric> Resistance; // 阻力线
Series<Numeric> Support; // 支撑线
Numeric ATRVal; // ATR(平均真实波幅)
Series<Numeric> myExitPrice; // 开仓BAR根据当时的ATR计算出的止盈价
Defs
Integer CalcuTradeLots() // 交易手数计算函数
{
Integer myLots;
If(LotsMode==3)
{
myLots = Max(1,IntPart((Portfolio_CurrentEquity*moneyrate/MarginRatio)/(Open*contractunit*bigpointvalue)));
}
Else If(LotsMode==2)
{
myLots = Max(1,IntPart(fixedmoney/(Open*contractunit*bigpointvalue)));
}
Else myLots = Lots;
return myLots;
}
Events
OnBar(ArrayRef<Integer> indexs)
{
// 计算当前K线的加权均值、阻力线和支撑线
WAvgPrice = (High + Low + (Close * 2)) / 4;
Resistance = (WAvgPrice * 2) - Low;
Support = (WAvgPrice * 2) - High;
// 输出指标
PlotNumeric("Resistance",Resistance[1]);
PlotNumeric("Support",Support[1]);
// 计算ATR
ATRVal = AvgTrueRange(ATRLength);
// 开仓
If(MarketPosition == 0 And Low <= Support[1] - MinMove * PriceScale And Vol > 0)
{
SellShort(0, Min(Open,Support[1] - MinMove * PriceScale));
// 平仓后调用交易手数计算函数
Integer TradeLots;
TradeLots = CalcuTradeLots();
Buy(TradeLots,Open);
}
// 开仓时根据开仓BAR的ATR计算止盈价
If(MarketPosition == -1 And BarsSinceEntry == 0)
{
myExitPrice = EntryPrice - ATRVal * ATRs;
}
// 平仓
If(MarketPosition == -1 And BarsSinceEntry > 0 And Vol > 0)
{
// 止盈出场
If(Low <= myExitPrice)
{
BuyToCover(0, Min(Open,myExitPrice));
Commentary("止盈出场");
// 平仓后调用交易手数计算函数
Integer TradeLots;
TradeLots = CalcuTradeLots();
SellShort(TradeLots,Open);
}
// 反向突破止损出场
Else If(High >= Resistance[1] + MinMove * PriceScale)
{
BuyToCover(0, Max(Open,Resistance[1] + MinMove * PriceScale));
Commentary("反转出场");
// 平仓后调用交易手数计算函数
Integer TradeLots;
TradeLots = CalcuTradeLots();
SellShort(TradeLots,Open);
}
}
}