2014年1月28日 星期二

超特別的隨機指標 Predictive Indicators (程式碼)

EasyTrader ArtNo 107
在網路上看到這篇文章 Predictive Indicators for Effective Trading Strategies ,作者提及一般在技術分析中作平滑化(Smoothen) 可能造成的延滯副作用,並將所觀察到的現象用不同的角度作詮釋,並提供了特殊的方法(並使用三角函數作運算) - SuperSmoother filter ,雖然不是很懂裡面計算的原理 , 不過既然有指標程式碼,我也好奇的拿來作測試


測試程式碼
inputs:Length( 20 ),UpBand( 0.8 ), DnBand(0 .2 ) ;
inputs: EntryType(1),ExitType(1),TradeProfit(0.05),TradeStopLoss(0.03),NBarL(2),NBarS(2);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0);
variables:
alpha1(0 ),HP( 0 ), a1( 0 ), b1( 0 ),c1( 0 ),c2( 0 ), c3( 0 ),Filt( 0 ),
HighestC( 0 ),LowestC( 0 ), count( 0 ), Stoc( 0 ), MyStochastic( 0 ) ;


MP = MarketPosition ;

if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;

PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;

{*******************************************}

{ My Stochastic Indicator © 2013 John F. Ehlers }
{
Inputs: Length(20);
Vars: alpha1(0), HP(0), a1(0), b1(0), c1(0), c2(0), c3(0), Filt(0),
HighestC(0), LowestC(0), count(0), Stoc(0), MyStochastic(0);
}
{Highpass filter cyclic components whose periods are shorter than 48 bars }
alpha1 = (Cosine(.707*360 / 48) + Sine (.707*360 / 48) - 1) / Cosine(.707*360 / 48);
HP = (1 - alpha1 / 2)*(1 - alpha1 / 2)*(Close - 2*Close[1] + Close[2]) + 2*(1 -
alpha1)*HP[1] - (1 - alpha1)*(1 - alpha1)*HP[2];

{Smooth with a Super Smoother Filter }
a1 = expvalue(-1.414*3.14159 / 10);
b1 = 2*a1*Cosine(1.414*180 / 10);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(HP + HP[1]) / 2 + c2*Filt[1] + c3*Filt[2];
HighestC = Filt;
LowestC = Filt;
For count = 0 to Length - 1 Begin
If Filt[count] > HighestC then HighestC = Filt[count];
If Filt[count] < LowestC then LowestC = Filt[count];
End;
Stoc = (Filt - LowestC) / (HighestC - LowestC);
MyStochastic = c1*(Stoc + Stoc[1]) / 2 + c2*MyStochastic[1] + c3*MyStochastic[2];
{Plot1(MyStochastic);
Plot2(.8);
Plot6(.2); }

{***********藍色字體為作者的指標程式碼**********************}


依據作者圖示寫的交易策略

if EntryType = 1 then Begin
   if MyStochastic crosses over UpBand then Sell next bar at Market
      else if MyStochastic crosses under DnBand then Buy next bar at Market ;
end;

if EntryType = 2 then Begin
   if MyStochastic > UpBand then Sell next bar at Lowest(Low,3) stop
       else if MyStochastic < DnBand then Buy next bar at Highest(High,3) stop ;
end;

if ExitType = 1 then SetStopLoss(PL * BigPointValue) ;

if ExitType = 2 then Begin
   SetStopLoss(PL * BigPointValue) ;
   SetProfitTarget(PF * BigPointValue) ;
end;

if ExitType = 3 then Begin
   if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
   if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;

if ExitType = 4 then Begin
   SetStopLoss(PL * BigPointValue) ;
   if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
   if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;

if IsBalanceDay then setExitonClose ;

基本設定: 台指期 60 min K 留倉 回測週期 2004/1~2013/12/31 交易成本 1200

A.原始策略


從績效曲線看起來還是有機會調整的

B.加入如意多空網



MagicQS024

沒有留言:

張貼留言