2013年12月9日 星期一

Ergodic indicator指標(續篇 ~ 策略程式碼)

EasyTrader ArtNo 069
在近期[程式交易≠HOLY GRAIL]發表了一個Ergodic indicator指標,版主 Wen大常有不錯的策略元素,因此借花獻佛拿來作測試,以下為使用60分K作的A,B兩個不同策略的測試

{ A 策略 -雙線交叉} 程式碼

Inputs:Price(close),AvgLen(9),r(7),s(27),u(1),Zeroline(0),SmthLen(7),TradeProfit(60000),TradeStopLoss(60000);
inputs:HighBand(20),LowBand(20),UpBand(2),DnBand(2);
Variable:_TSI (0),color(0),Numerator(0),Denominator(0),AvgTSI(0),Avg2(0),ErgDiff(0);
Vars:MP(0),IsBalanceDay(false) ;

MP = MarketPosition ;

if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;
{ Numerator }
Numerator = 100*XAverage(XAverage(XAverage(Price-Price[1],r),s),u) ;
{ Denominator }
Denominator = XAverage(XAverage(XAverage(AbsValue(Price-Price[1]),r),s),u) ;

If Denominator <> 0 then _TSI = Numerator / Denominator
   else  _TSI = 0;

AvgTSI= XAverage(_TSI, SmthLen);
avg2 = xAverage(AvgTSI,AvgLen);
ErgDiff = AvgTSI-avg2 ;

if AvgTSI Cross over avg2 and AvgTSI < -DnBand then  Buy ("Bull") next bar at Market ;
if AvgTSI Cross under avg2 and AvgTSI > UpBand then  Sell ("Bear") next bar at Market ;

SetStopLoss(TradeStopLoss) ;
SetProfitTarget(TradeProfit) ;

if IsBalanceDay then SetExitonClose ;




{ B 策略- 上下通道 } 程式碼
Inputs:Price(close),AvgLen(9),r(7),s(27),u(1),Zeroline(0),SmthLen(7),TradeProfit(60000),TradeStopLoss(60000);
inputs:HighBand(20),LowBand(20),UpBand(2),DnBand(2);
Variable:_TSI (0),color(0),Numerator(0),Denominator(0),AvgTSI(0),Avg2(0),ErgDiff(0);
Vars:MP(0),IsBalanceDay(false) ;

MP = MarketPosition ;

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

{ Numerator }
Numerator = 100*XAverage(XAverage(XAverage(Price-Price[1],r),s),u) ;

{ Denominator }
Denominator = XAverage(XAverage(XAverage(AbsValue(Price-Price[1]),r),s),u) ;

If Denominator <> 0 then _TSI = Numerator / Denominator
    else  _TSI = 0;
AvgTSI= XAverage(_TSI, SmthLen);
avg2 = xAverage(AvgTSI,AvgLen);
ErgDiff = AvgTSI-avg2 ;

if AvgTSI Cross over UpBand then  Buy ("Bull") next bar at Market ;
if AvgTSI Cross under -DnBand then  Sell ("Bear") next bar at Market ;


if Mp > 0 and AvgTSI Cross over HighBand then Sell {Exitlong} ("Bullexit") next bar at Market ;
if MP < 0 and AvgTSI Cross under -LowBand then Buy {ExitShort} ("Bearexit") next bar at Market ;

SetStopLoss(TradeStopLoss) ;
SetProfitTarget(TradeProfit) ;

if IsBalanceDay then SetExitonClose ;



沒有留言:

張貼留言