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次插入该指标并适当转换指标数量实现。

b_1B4487A8FC8484E75FC262E3B539FF4C

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 )
PF2) and ( PF2 >= PF3 ) ) ) )
and ( F3 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 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 = 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 ] 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 ( 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


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 David 的頭像
    David

    FUTURE ATM

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