//------------------------------------------------------------------------
// 简称: CustomKLineDrawing
// 名称: 自定义K线绘制
// 类别: 公式应用
// 类型: 内建应用
// 输出:
//------------------------------------------------------------------------
Params
Numeric Threshold(0.05); // 涨跌幅阈值 5%
Vars
Series<Numeric> OpenPrice; // 开盘价
Series<Numeric> HighPrice; // 最高价
Series<Numeric> LowPrice; // 最低价
Series<Numeric> ClosePrice;// 收盘价
Series<Numeric> LastClose; // 上一根K线的收盘价
Numeric CurrentOpen; // 当前K线的开盘价
Numeric CurrentHigh; // 当前K线的最高价
Numeric CurrentLow; // 当前K线的最低价
Numeric CurrentClose; // 当前K线的收盘价
Bool NewBar; // 是否进入新K线
Events
OnInit()
{
// 初始化变量
OpenPrice = 0;
HighPrice = 0;
LowPrice = 0;
ClosePrice = 0;
LastClose = 0;
CurrentOpen = 0;
CurrentHigh = 0;
CurrentLow = 0;
CurrentClose = 0;
NewBar = True;
}
OnBar(ArrayRef<Integer> indexs)
{
If(NewBar)
{
// 进入新的K线
CurrentOpen = Open;
CurrentHigh = High;
CurrentLow = Low;
CurrentClose = Close;
NewBar = False;
}
Else
{
// 更新当前K线的最高价和最低价
CurrentHigh = Max(CurrentHigh, High);
CurrentLow = Min(CurrentLow, Low);
CurrentClose = Close;
}
// 计算当前K线的涨跌幅
Numeric ChangePercent = (CurrentClose - CurrentOpen) / CurrentOpen;
// 判断是否满足涨跌幅阈值
If(Abs(ChangePercent) >= Threshold Or Time % 300 == 0)
{
// 满足条件,进入下一根K线
OpenPrice[0] = CurrentOpen;
HighPrice[0] = CurrentHigh;
LowPrice[0] = CurrentLow;
ClosePrice[0] = CurrentClose;
LastClose = CurrentClose;
NewBar = True;
}
// 输出当前K线的信息
Commentary("Open: " + Text(OpenPrice[0]) + ", High: " + Text(HighPrice[0]) + ", Low: " + Text(LowPrice[0]) + ", Close: " + Text(ClosePrice[0]));
}
//------------------------------------------------------------------------
报什么错?