//------------------------------------------------------------------------
// 简称: ZigZag
// 名称: 之字转向
// 类别: 策略应用
// 类型: 内建应用
//------------------------------------------------------------------------
Params
Numeric RetracePct(2);
Vars
Series<Numeric> SwingPrice;
Numeric SwingHighPrice;
Numeric SwingLowPrice;
Series<Numeric> PreBar(0);
Series<Numeric> UpDn(0);
Bool SaveSwing(False);
Bool NewTL(False);
Bool UpdateTL(False);
global array<numeric> price_record_high;
global array<numeric> price_record_low;
series<Numeric> i;
series<Numeric> j;
Events
OnBar(ArrayRef<Integer> indexs)
{
If(CurrentBar == 0)
{
SwingPrice = Close;
i = 0;
j = 0;
}
SwingHighPrice = SwingHigh( 1, Close, 1, 2);
SwingLowPrice = SwingLow( 1, Close, 1, 2 );
If (SwingHighPrice <> -1)
{
If(UpDn <= 0 && SwingHighPrice >= SwingPrice * (1 + RetracePct * 0.01))
{
UpDn = 1;
NewTL = True;
SaveSwing = True;
price_record_low[j] = SwingPrice;
j = j + 1;
}
Else If(UpDn == 1 && SwingHighPrice >= SwingPrice)
{
UpdateTL = True;
SaveSwing = True;
}
If(SaveSwing)
{
SwingPrice = SwingHighPrice;
PreBar = CurrentBar;
}
}
Else If(SwingLowPrice <> -1)
{
If(UpDn >= 0 && SwingLowPrice <= SwingPrice * (1 - RetracePct * 0.01))
{
UpDn = -1;
NewTL = True;
SaveSwing = True;
price_record_high[i] = SwingPrice;
i = i + 1;
}
Else If(UpDn == -1 && SwingLowPrice <= SwingPrice)
{
UpdateTL = True;
SaveSwing = True;
}
If(SaveSwing )
{
SwingPrice = SwingLowPrice;
PreBar = CurrentBar;
}
}
If( NewTL)
{
PlotAuto("ZigZag", SwingPrice, 0, Color2(), -1, -1, Enum_3Pix, 1);
}
Else If(UpdateTL)
{
If (UpDn == UpDn[1])
{
Unplot("ZigZag", PreBar - PreBar[1] + 1);
PlotAuto("ZigZag", SwingPrice, 0, Color2(), -1, -1, Enum_3Pix, 1);
}
Else
{
PlotAuto("ZigZag", SwingPrice, 0, Color2(), -1, -1, Enum_3Pix, 1);
}
}
If(BarStatus == 2)
{
print("高点");
print(TextArray(price_record_high));
print("低点");
print(TextArray(price_record_low));
}
}
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08
// 版权所有 TradeBlazer Software 2003-2025
// 更改声明 TradeBlazer Software保留对TradeBlazer平
// 台每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------刘老师👍