//------------------------------------------------------------------------
// 简称: PPSuperTrend
// 名称: 枢轴点超级趋势
// 类别: 公式应用
// 类型: 用户应用
//------------------------------------------------------------------------
Params
Numeric PivotPeriod(2); // 枢轴点周期
Numeric ATRFactor(3); // ATR因子
Numeric ATRPeriod(10); // ATR周期
Bool ShowPivotPoints(False); // 显示枢轴点
Bool ShowLabels(True); // 显示买卖标签
Bool ShowCenterLine(False); // 显示中心线
Bool ShowSupportResistance(False); // 显示支撑阻力
Vars
Series<Numeric> ph; // 枢轴高点
Series<Numeric> pl; // 枢轴低点
Series<Numeric> center; // 中心线
Series<Numeric> lastPP; // 最后枢轴点
Series<Numeric> upLine; // 上轨
Series<Numeric> dnLine; // 下轨
Series<Numeric> tUp; // 趋势上轨
Series<Numeric> tDown; // 趋势下轨
Series<Numeric> trend; // 趋势方向
Series<Numeric> trailingSL; // 跟踪止损线
Series<Numeric> support; // 支撑位
Series<Numeric> resistance; // 阻力位
Series<Bool> buySignal; // 买入信号
Series<Bool> sellSignal; // 卖出信号
Numeric atrVal; // ATR值
Events
OnBar(ArrayRef<Integer> indexs)
{
// 计算枢轴点
ph = Highest(High, PivotPeriod);
pl = Lowest(Low, PivotPeriod);
// 确定最后枢轴点
If (ph != InvalidNumeric)
{
lastPP = ph;
}
Else If (pl != InvalidNumeric)
{
lastPP = pl;
}
Else
{
lastPP = InvalidNumeric;
}
// 计算动态中心线
If (lastPP != InvalidNumeric)
{
If (center == InvalidNumeric)
{
center = lastPP;
}
Else
{
center = (center * 2 + lastPP) / 3;
}
}
// 计算ATR
atrVal = AvgTrueRange(ATRPeriod);
// 计算上下轨道
If (center != InvalidNumeric)
{
upLine = center - (ATRFactor * atrVal);
dnLine = center + (ATRFactor * atrVal);
}
// 计算超级趋势
If (CurrentBar == 0)
{
tUp = upLine;
tDown = dnLine;
trend = 1;
}
Else
{
// 更新趋势上轨
If (Close[1] > tUp[1])
{
tUp = Max(upLine, tUp[1]);
}
Else
{
tUp = upLine;
}
// 更新趋势下轨
If (Close[1] < tDown[1])
{
tDown = Min(dnLine, tDown[1]);
}
Else
{
tDown = dnLine;
}
// 确定趋势方向
If (Close > tDown[1])
{
trend = 1;
}
Else If (Close < tUp[1])
{
trend = -1;
}
Else
{
trend = trend[1];
}
}
// 计算跟踪止损线
trailingSL = IIF(trend == 1, tUp, tDown);
// 生成买卖信号
buySignal = (trend == 1) And (trend[1] == -1);
sellSignal = (trend == -1) And (trend[1] == 1);
// 更新支撑阻力位
If (pl != InvalidNumeric)
{
support = pl;
}
Else
{
support = support[1];
}
If (ph != InvalidNumeric)
{
resistance = ph;
}
Else
{
resistance = resistance[1];
}
// 绘制超级趋势线
If (trend == 1 And trend[1] == 1)
{
PlotNumeric("SuperTrend", trailingSL, Green);
}
Else If (trend == -1 And trend[1] == -1)
{
PlotNumeric("SuperTrend", trailingSL, Red);
}
Else
{
PlotNumeric("SuperTrend", trailingSL);
}
// 绘制中心线
If (ShowCenterLine And center != InvalidNumeric)
{
If (center < (High + Low) / 2)
{
PlotNumeric("CenterLine", center, Blue);
}
Else
{
PlotNumeric("CenterLine", center, Red);
}
}
// 绘制枢轴点
If (ShowPivotPoints)
{
If (ph != InvalidNumeric)
{
PlotNumeric("PivotHigh", ph, Red);
}
If (pl != InvalidNumeric)
{
PlotNumeric("PivotLow", pl, Green);
}
}
// 绘制买卖标签
If (ShowLabels)
{
If (buySignal)
{
PlotString("BuyLabel", "Buy", Low, Green);
}
If (sellSignal)
{
PlotString("SellLabel", "Sell", High, Red);
}
}
// 绘制支撑阻力线
If (ShowSupportResistance)
{
If (support != InvalidNumeric)
{
PlotNumeric("Support", support, Green);
}
If (resistance != InvalidNumeric)
{
PlotNumeric("Resistance", resistance, Red);
}
}
}
//------------------------------------------------------------------------
// 编译版本 TBQuant
// 版权所有 TradeBlazer Software 2003-2025
// 更改声明 TradeBlazer Software保留对TradeBlazer平台每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------用TBQuant3试试——官网下载
我把你的加载到Q3上没出现你说的情况
观察