[交易系統] Vervoort trailing stop strategy

Here is Sylvain Vervoort's trailing resistance and stop (VTSR) strategy :

inputs:
        Quantity( 100 ),
        InitialMonth( 1 ),
        InitialDay( 1 ),
        InitialYear( 2008 ),
        MinGapPct( 0.13 ),
        StopOffHighPct( 0.55 ),
        MaxLossPct( 10 ),
        MaxLossResetPct( 5 ),
        ATR_Period( 10 ),
        ATR_Factor( 2.8 ) ;

variables:
        HiLo( 0 ),
        HRef( 0 ),
        LRef( 0 ),
        HiLoHRefMax( 0 ),
        HiLoHRefMaxLRefMax( 0 ),
        ATRMod( 0 ),
        Resistance( 0 ),
        Loss( 0 ),
        LineNum( 0 ),
        ReturnVal( 0 ),
        WaitingForEntry( true ),
        Trends( 0 ),
        Support( 0 ) ;

HiLo = iff( High - Low < 1.5 * Average( High - Low,
ATR_Period ), High - Low, 1.5 * Average( High - Low,
ATR_Period ) ) ;
HRef = iff( Low <= High[1], High - Close[1],( High -
Close[1] ) - 0.5 * ( Low - High[1] ) ) ;
LRef = iff( High >= Low[1], Close[1] - Low, ( Close[1] -
Low ) - 0.5 * ( Low[1] - High ) ) ;
HiLoHRefMax = Maxlist( HiLo, HRef ) ;
HiLoHRefMaxLRefMax = Maxlist( HiLoHRefMax, LRef ) ;
ATRMod = XAverageOrig( HiLoHRefMaxLRefMax,
ATR_Period ) ;
Loss = ATR_Factor * ATRMod ;
Resistance = Close + Loss ;

if Low >= Low[2]
        and Low[1] >= Low[2]
        and Low[3] >= Low[2]
        and Low[4] >= Low[2]
then
        Support = Low[2]
else if Low > High[1] * ( 1 + 0.01 * MinGapPct ) then
Support = High[1] * ( 1 - 0.01 * StopOffHighPct )
else if Low > Support[1] * ( 1 + 0.01 * MaxLossPct )
then
        Support = Support[1] * ( 1 + 0.01 *
         MaxLossResetPct ) ;

if High > Trends[1] and High[1] > Trends[1] then
Trends = MaxList( Trends[1], Support )
else if High < Trends[1] and High[1] < Trends[1] then
Trends = Minlist( Trends[1], Resistance )
else if High >= Trends[1] then
        Trends = Support
else
        Trends = Resistance ;

if ( Year( Date ) + 1900 = InitialYear
        and Month( Date ) >= InitialMonth
and DayOfMonth( Date ) >= InitialDay ) or
        Year( Date ) + 1900 > InitialYear
then
        begin
if MarketPosition = 0 and High > Trends[1] and
         Trends[1] > 0 then
                begin
Buy Quantity shares this bar Close ;
LineNum = TL_New( Date[1], Time[1], Trends[1],
                 Date, Time, Trends ) ;
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
                end
else if MarketPosition = 1 and High < Trends[1] then
                begin
Sell Quantity shares this bar at Close ;
LineNum = TL_New( Date[1], Time[1], Trends[1],
                 Date, Time, Trends ) ;
ReturnVal = TL_SetColor( LineNum, Magenta ) ;
                end
        else if Trends[1] > 0 then
                begin
LineNum = TL_New( Date[1], Time[1], Trends[1],
                 Date, Time, Trends ) ;
                if Close > Trends then
ReturnVal = TL_SetColor( LineNum, Magenta )
                else
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
                end ;
        end ;

 


another strategy :
{ Modified ATR Trailing Stop }
inputs:
TrailType ( 1 ), { enter 1 for modified version, any
other number for unmodified version }
        ATR_Period( 5 ),
        ATR_Factor( 3.5 ),
        Quantity( 100 ),
        InitialMonth( 1 ),
        InitialDay( 1 ),
        InitialYear( 2009 ),
FirstTrade( 1 ) ; { enter 1 for long, any other
         number for short }

variables:
        Loss( 0 ),
        HiLo( 0 ),
        HRef( 0 ),
        LRef( 0 ),
        HiLoHRefMax( 0 ),
        HiLoHRefMaxLRefMax( 0 ),
        ATRMod( 0 ),
        WaitingForEntry( true ),
        Trail( 0 ),
        LineNum( 0 ),
        ReturnVal( 0 ) ;

if TrailType <> 1 then
Loss = ATR_Factor * AvgTrueRange( ATR_Period )
else
        begin
HiLo = iff( High - Low < 1.5 * Average( High - Low,
ATR_Period ), High - Low, 1.5 * Average( High -
         Low, ATR_Period ) ) ;
HRef = iff( Low <= High[1], High - Close[1],( High -
Close[1] ) - 0.5 * ( Low - High[1] ) ) ;
LRef = iff( High >= Low[1], Close[1] - Low,
( Close[1] - Low ) - 0.5 * ( Low[1] - High ) ) ;
        HiLoHRefMax = Maxlist( HiLo, HRef ) ;
HiLoHRefMaxLRefMax = Maxlist( HiLoHRefMax, LRef ) ;
ATRMod = XAverage( HiLoHRefMaxLRefMax, 2 *
         ATR_Period - 1 ) ;
        Loss = ATR_Factor * ATRMod ;
        end ;

if WaitingForEntry
and Year( Date ) + 1900 >= InitialYear
        and Month( Date ) >= InitialMonth
        and DayOfMonth( Date ) >= InitialDay
then
        begin
        if FirstTrade = 1 then
                begin
Buy Quantity shares this bar Close ;
            WaitingForEntry = false ;
                Trail = Close - Loss ;
                end
        else
                begin
Sell short Quantity shares this bar at Close ;
WaitingForEntry = false ;
                Trail = Close + Loss ;
                end ;
        end
else if WaitingForEntry[1] = false then
        begin
if Close > Trail[1] and Close[1] > Trail[2] then
{ continued long }               
Trail = MaxList( Trail[1], Close - Loss )
else if Close < Trail[1] and Close[1] < Trail[2]
         then
                { continued short }
Trail = MinList( Trail[1], Close + Loss )
        else if Close > Trail[1] then  
                { close is above trail }
                Trail = Close - Loss
        else
                Trail = Close + Loss ;

if MarketPosition = -1 and Close > Trail and
         Trail > 0 then
                begin
Buy Quantity shares this bar Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
                end
else if MarketPosition = 1 and Close < Trail then
                begin
Sell short Quantity shares this bar at Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Magenta ) ;
                end
        else if Trail[1] > 0 then
                begin
LineNum = TL_New( Date[1], Time[1], Trail[1],
                 Date, Time, Trail ) ;
                if Close > Trail then
ReturnVal = TL_SetColor( LineNum, Magenta )
                else
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
                end ;
        end ;

 

arrow
arrow
    全站熱搜

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