From:交易學 TRADESTATION: AUTOMATIC TRENDLINES Giorgos Siligardos' article in this issue, "Building Automatic Trendlines," outlines an algorithmic trendline-drawing technique. Giorgos Siligardos关于此主题的文章,“建立自动趋势线”,描述了趋势线绘制技术的一种算法。 We have converted the three blocks of pseudo-code provided in the article into an EasyLanguage indicator and two functions. Each automatic trendline is based on a "percent retracement" threshold. The article suggests comparing 5%, 10%, 20%, 50%, and 80% retracements, which can be accomplished by inserting the indicator five times and appropriately converting the indicator amounts. 我们已经把文章中的三块伪代码(pseudo-code)转换为EasyLanguage指标和两个函数。每条自动趋势线基于“百分比回撤”阈值("percent retracement" threshold)。文中建议比较5%、10%, 20%, 50%和80%回撤,可以通过5次插入该指标并适当转换指标数量实现。 FIGURE 1: TRADESTATION, AUTOMATIC TRENDLINES. Here are sample weekly charts of Big Lots (BIG) and BJ Services (BJS) with automatic trendlines drawn using the Siligardos algorithm. The code for the indicator is shown here. A sample chart is shown in Figure 1. Code for the functions can be found in the EasyLanguage Library at TradeStation.com. To download the EasyLanguage indicator and function code for this article, search for the file "SiligardosAT.eld." Indicator: Siligardos Autotrend inputs: Threshold( 30 ), Lookback( 300 ) ; variables: TrendLineBuilt( false ), PivotsFound( 0 ), f( 0 ), b( 0 ), x( 0 ), y( 0 ), F1( 0 ), F2( 0 ), F3( 0 ), PF1( 0 ), PF2( 0 ), PF3( 0 ) ; arrays: PivotArray[500]( 0 ), PivotType[4]( 0 ), PivotPosition[4]( 0 ), SI[500]( 0 ) ; if LastBarOnChart then begin for x = 1 to Lookback begin PivotArray[x] = 0 ; end ; F1 = 1 ; F2 = F1 ; PF1 = Close[F1] ; PF2 = Close[F2] ; {find the first move greater than threshold percent} while ( 100 *AbsValue( PF1 - PF2 ) / MinList( PF1, PF2 ) < Threshold and ( F2 < Lookback ) ) begin F2 = F2 + 1 ; PF2 = Close[F2] ; end ; F3 = F2 ; PF3 = Close[F3] ; while F1 < Lookback begin while ( ( (100 * AbsValue( PF2 - PF3 ) / MinList( PF2, PF3 ) < Threshold ) or ( ( ( PF1 < PF2 ) and ( PF2 <= PF3 ) ) or ( ( PF1>PF2) and ( PF2 >= PF3 ) ) ) ) and ( F3 < Lookback ) ) begin if ( ( ( PF1 < PF2 ) and ( PF2 <= PF3 ) ) or ( ( PF1 > PF2 ) and ( PF2 >= PF3 ) ) ) then begin F2 = F3 ; PF2 = Close[F2] ; end ; F3 = F3 + 1 ; PF3 = Close[F3] ; end ; if ( ( F3 = Lookback ) ) then begin F1 = F2 ; F2 = F3 ; PF1 = Close[F1] ; PF2 = Close[F2] ; end ; if ( F2 > F1 ) then begin PivotArray[F2] = 1 ; F1 = F2 ; F2 = F3 ; PF1 = Close[F1] ; PF2 = Close[F2] ; end ; end ; PivotArray[1] = 0 ; PivotArray[Lookback] = 0 ; end ; if LastBarOnChart then begin x = 1 ; y = 1 ; while ( y < Lookback ) begin y = y + 1 ; if ( ( PivotArray[ y ] <> 0 ) or ( y = Lookback ) ) then begin b = ( Close[y] - Close[x] ) / ( y - x ) ; for f = x to y begin SI[f] = ( b * ( f - x ) + Close[x] ) ; end ; x = y ; end ; end ; F = 2 ; {locate pivots} PivotsFound = 0 ; while ( ( F < Lookback - 2 ) and ( PivotsFound < 4 ) ) begin if ( ( SI[f] <= SI[ f + 1 ] ) and ( SI[ f - 1 ] >= SI[f] ) ) then begin PivotsFound = PivotsFound + 1 ; PivotType[ 5 - PivotsFound ] = + 1 ; PivotPosition[ 5 - PivotsFound ] = F ; end ; if ( ( SI[f] >= SI[ f + 1 ] ) and (SI[ f - 1 ] <= SI[f] ) ) then begin PivotsFound = PivotsFound + 1 ; PivotType[ 5 - PivotsFound ] = - 1 ; PivotPosition[ 5 - PivotsFound ] = f ; end ; F = F + 1 ; end ; if ( PivotsFound = 4 ) then begin if ( PivotType[2] = 1 ) and ( PivotType[4] = 1 ) and ( Close[ PivotPosition[2] ] < Close[ PivotPosition[4] ] ) and ( MaxList( Close[ PivotPosition[2] ], Close[ PivotPosition[4] ] ) < MaxList( High[ PivotPosition[4] ],Close[0] ) ) then begin Value1 = TrendlineUp( Lookback, PivotPosition[2],PivotPosition[4] ) ; TrendlineBuilt = true ; end else if ( PivotType[2] = -1 ) and ( PivotType[4] = -1 ) and ( Close[ PivotPosition[2] ] > Close[ PivotPosition[4] ] ) and ( MinList( Close[ PivotPosition[2] ], Close[ PivotPosition[4] ] ) > MinList ( Close[ PivotPosition[4] ], Close[0] ) ) then begin Value1 = TrendlineDown( Lookback, PivotPosition[2], PivotPosition[4] ); TrendlineBuilt = true ; end else Print( " Lookback trendline can be drawn,", "Threshold = ", Threshold ) ; end ; if ( PivotsFound >= 3 ) and TrendLineBuilt = false then begin if ( PivotType[1] = 1 ) and ( PivotType[3] = 1 ) and ( Close[ PivotPosition[1] ] < Close[ PivotPosition[3] ] ) and ( MaxList( Close[ PivotPosition[1] ], Close[ PivotPosition[3] ] ) < MaxList( Close[ PivotPosition[3] ], Close[0] ) ) then Value1 = TrendlineUp( Lookback, PivotPosition[1], PivotPosition[3] ) else if ( PivotType[1] = -1 ) and ( PivotType[3] = -1 ) and ( Close[PivotPosition[1] ] > Close[ PivotPosition[3] ] ) and ( MinList( Close[ PivotPosition[1] ], Close[ PivotPosition[3] ] ) > MinList( Close[ PivotPosition[3] ], Close[0] ) ) then Value1 = TrendlineDown( Lookback, PivotPosition[1], PivotPosition[3] ) else Print( "No trendline can be drawn,", "Threshold = ", Threshold ) ; end else Print( "No trendline can be drawn,", "Threshold = ", Threshold ) ; if ( PivotsFound < 3 ) then Print( "No Point Milestones Can Be Found,", "Threshold = ", Threshold ) ; end; --------------------------------- --Mark Mills TradeStation Securities, Inc. A subsidiary of TradeStation Group, Inc. www.TradeStationWorld.com ---------------------------------
文章標籤
全站熱搜
創作者介紹
創作者 David 的頭像
David

FUTURE ATM

David 發表在 痞客邦 留言(0) 人氣(1,035)