TS里的ZIGZAG,是借助最小尺度的SWINGHIGH和SWINGLOW来依次计算的,比起MS的ZIGZAG,好在可以同时包括高点和低点,而这是ZIGZAG方法的本意,所以很不错。 可遗憾的是,在我布这个指标的过程中,经常能够发现错误的线条,如图所示。因为指标比较复杂,自己又不太懂EASY LANGUAGE,这里寻找哪里出了问题就非常困难,不知道有没有TS高手能指出,这个问题的原因在哪里?
后来发现,是因为单根K线既出现了高点又出现了低点,幅度大于滤波尺寸,因而引起双重确认转折点,就出了问题。 我增加了一个SW变量,使转折点确认只发生一种,就没有问题了! 改进后的代码: {*********************************************************************** Description : This Indicator plots ZigZag Percent Provided By : Snow Inc. (c) Copyright 2005 ************************************************************************} Inputs: WavePcnt(0.5), Color(Green), Thicknes(0); Variables: RP(0), RPDate(0), RPTime(0), ZigZag(0), Switch(0), NextZig(0), SW(0); IF CurrentBar = 1 Then Begin RP = MedianPrice; RPDate = Date; RPTime = Time; NextZig = Text_New(Date, Time, 0, NumToStr(WavePcnt, 0)+"%-"); Text_SetColor(NextZig, Color); End; SW=0; IF High > High[1] Then Begin {New High found} IF Switch <> -1 AND High >= RP * (1+(WavePcnt*.01)) Then Begin {If it is uptrend seek and this SwingHigh is WavePcnt higher than RP} Condition1 = True; {New up Reversal Point confirmed} Switch = -1; {Start downtrend seek} Condition2 = True; {RP to update} End; IF Condition1 = False AND Switch = -1 AND High >= RP Then Begin {New up RP has not been confirmed, downtrendseek, SwingHigh is still higher than RP} TL_SetEnd(ZigZag, Date, Time, High); {Extend trendline towards this SwingHigh} Condition2 = True; {RP to update} End; IF Condition2 Then Begin {If RP to update} Condition2 = False; {Reset RP update status} RP = High; {Update Reversal Point to SwingHigh} RPDate = Date; {Update Reversal Point Date} RPTime = Time; {Update Reversal Point Time} SW=1; End; End; IF Low < Low[1] and SW = 0 Then Begin {New Low Found} IF Switch <> 1 AND Low <= RP * (1-(WavePcnt*.01)) Then Begin {If it is downtrend seek and this SwingLow is WavePcnt Lower than RP} Condition1 = True; {New RP confirmed} Switch = 1; {Start uptrend seek} Condition2 = True; {RP to update} End; IF Condition1 = False AND Switch = 1 AND Low <= RP Then Begin {New RP has not been confirmed, uptrend seek, but SwingLow is still Lower than RP} TL_SetEnd(ZigZag, Date, Time, Low); {Extend trendline towards this new SwingLow} Condition2 = True; {RP to update} End; IF Condition2 Then Begin {Update Reversal Point} Condition2 = False; {Reset RP update status} RP = Low; {Update Reversal Point to SwingLow} RPDate = Date; {Update Reversal Point Date} RPTime = Time; {Update Reversal Point Time} End; End; IF Condition1 Then Begin {New RP confirmed} Condition1 = False; {Reset RP confirmed status} ZigZag = TL_New(RPDate, RPTime, RP, RPDate[1], RPTime[1], RP[1]); {Draw new trendline and pass its ID to zigzag variable} TL_SetSize(ZigZag, Thicknes); TL_SetColor(ZigZag, Color); TL_SetExtRight(ZigZag, False); TL_SetExtLeft(ZigZag, False); { IF False Then Plot1[1](RP, "RP");} End; IF Switch = 1 Then Begin {If uptrend seek then} Text_SetLocation(NextZig, Date, Time, RP * (1+(WavePcnt*.01))); Text_SetStyle(NextZig, 1, 2); End; IF Switch = -1 Then Begin Text_SetLocation(NextZig, Date, Time, RP * (1-(WavePcnt*.01))); Text_SetStyle(NextZig, 1, 2); End;