//------------------------------------------------------------------------
// 简称: ZigZag
// 名称: 之字转向
// 类别: 策略应用
// 类型: 内建应用
//------------------------------------------------------------------------
Params
Numeric RetracePct(2);
Vars
series<numeric> swingprice;
series<numeric> updn;
series<numeric> bar_index;
plot pen1;
Events
OnInit()
{
pen1.setOption("TL", "color", yellow);
}
OnBar(ArrayRef<Integer> indexs)
{
PlotString("barind",text(currentbar));
If(CurrentBar == 0)
{
SwingPrice = Close;
//PlotNumeric("TL",close);
pen1.line("TL", close);
return;
}
If(CurrentBar == 1)
{
If(close > swingprice) updn = 1;
else updn = -1;
//PlotNumeric("TL",close);
pen1.line("TL", close);
bar_index = CurrentBar;
swingprice = close;
}
Else
If(updn == 1)//上涨趋势
{
//If(close > swingprice)//需要更新新高
If(close[1] > swingprice)//需要更新新高
{
//swingprice = close;
swingprice = close[1];
//Unplot("TL", CurrentBar - bar_index);
Commentary("bar_index:" + text(bar_index));
numeric point =date[CurrentBar - bar_index] + time[CurrentBar - bar_index];
Commentary("point:"+text(point));
pen1.clear("TL", point, point);
//PlotNumeric("TL", close,0,Yellow);
pen1.line("TL", date[1]+time[1],swingprice);
bar_index = CurrentBar-1;
Commentary("更新新高");
}
Commentary("retractprice:"+text(swingprice * (1 - RetracePct * 0.01)));
//If(close < swingprice * (1 - RetracePct * 0.01)) //发生转折
If(close[1] < swingprice * (1 - RetracePct * 0.01)) //发生转折
{
updn = -1;
swingprice = close[1];
pen1.line("TL", date[1]+time[1],swingprice);
bar_index = CurrentBar-1;
Commentary("多转空");
}
}
Else //下跌趋势
{
//If(close < swingprice)//需要更新新低
If(close[1] < swingprice)//需要更新新低
{
swingprice = close[1];
//swingprice = close;
//Unplot("TL", CurrentBar - bar_index);
numeric point =date[CurrentBar - bar_index] + time[CurrentBar - bar_index];
pen1.clear("TL", point, point);
//PlotNumeric("TL", close,0,Yellow);
pen1.line("TL", date[1]+time[1],swingprice);
bar_index = CurrentBar-1;
Commentary("更新新低");
}
//If(close > swingprice * (1 + RetracePct * 0.01)) //发生转折
If(close[1] > swingprice * (1 + RetracePct * 0.01)) //发生转折
//If(close > swingprice * (1 + RetracePct * 0.01)) //发生转折
{
updn = 1;
swingprice = close[1];
//pen1.line("TL", close);
pen1.line("TL", date[1]+time[1],swingprice);
bar_index = CurrentBar-1;
Commentary("空转多");
}
}
Commentary("updn:" + text(updn));
Commentary("swingprice:" + text(swingprice));
Commentary("CurrentBar:" + text(CurrentBar));
Commentary("bar_index:" + text(bar_index));
}
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08
// 版权所有 TradeBlazer Software 2003-2025
// 更改声明 TradeBlazer Software保留对TradeBlazer平
// 台每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------