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 ;


2 留言:

WEN 提到...

我的策略元素來自於觀察多市場及海外網站,最近挖來一堆書籍,消化完後再跟讀者分析裡面的精華之所在。

籌碼會說話 提到...

此策略經過測試績效的確不錯 , 再稍加修改應該就可以直接上線了 !

張貼留言

如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!

----------------------------------------------------------------------------------------------------
網站聲明(Disclaimer)
本教學網站內所提供之程式碼(包括函數、指標、訊號)屬開放程式碼,用意在於讓使用者學習程式語法之撰寫,使用者可以任意修改語法內容並調整參數。本網站所有之內容(包括文章、影片、歷史紀錄、程式碼、教材)限用於個人學習使用,請勿轉寄、濫用,嚴禁私自串接帳戶交易。
-------------------------------------------------------------------------------------------------