2013年12月18日 星期三

●卡瑪利拉樞軸點 Camarilla Pivot Point (策略程式碼)

EasyTrader ArtNo 076
進出場圖解說明(看圖說故事)


1.開盤價在 SP3/RT3 之間
作多: 等價格跌破 SP3再回漲到 SP3 以上買進 , 停損設在 SP4 ,RT1/RT2/RT3 都可以是停利位置
作空: 等價格漲過 RT3再回跌到 RT3 以下賣出 , 停損設在 RT4 ,SP1/SP2/SP3 都可以是停利位置

2.開盤價在 RT3 與 RT4 之間
作多: 當價格突破 RT4 買進, 停損設在RT3 或是停損利在RT4 的 -0.5% ~ 1%之間
作空: 當價格跌破 RT3 賣出, 停損設在RT4 停利可設在 SP1/SP2/SP3(視前日振幅調整)

3.開盤價在 SP3 與 SP4 之間
作多: 當價格突破 SP3 買進, 停損設在SP4 停利可設在 RT1/RT2/RT3(視前日振幅調整)
作空: 當價格跌破 SP4 賣出, 停損設在SP3 或是停損利在SP4 的 -0.5% ~ 1%之間

4.開盤價在 RT4 或 SP4 之外
等價格回落/反彈到區間內再依據前述原則交易

測試程式碼
input:BarNo(1),BaseRatio(1.1),Factor(1),TradeProfit(0.05),TradeStopLoss(0.02),NbarL(6),NbarS(6) ;
input:FastLen(5),SlowLen(20),Type(1),HLRange(100);
Vars:Pivot(0),SP1(0),SP2(0),SP3(0),SP4(0),SP5(0),RT1(0),RT2(0),RT3(0),RT4(0),RT5(0),HL(0) ;
Vars: MP(0),IsBalanceDay(false) ,PF(0),PL(0),OpenPrice(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 ;

if DataCompression > 1 then Begin
HL = Range[1] ;
Pivot = TypicalPrice[1] ;
RT1 = Close[1] + HL*BaseRatio/12*Factor ;
RT2 = Close[1] + HL*BaseRatio/6*Factor ;
RT3 = Close[1] + HL*BaseRatio/4*Factor ;
RT4 = Close[1] + HL*BaseRatio/2*Factor ;
if Low[1] <> 0 then RT5 = (High[1]/Low[1])*Close[1]*BaseRatio ;
SP1 = Close[1] - HL*BaseRatio/12*Factor ;
SP2 = Close[1] - HL*BaseRatio/6*Factor ;
SP3 = Close[1] - HL*BaseRatio/4*Factor ;
SP4 = Close[1] - HL*BaseRatio/2*Factor ;
SP5 = (Close[1]*2 - RT5)*BaseRatio ;
Condition1 = Close > Open and Open > Close[1] ;
Condition2 = Close < Open and Open < Close[1] ;
OpenPrice = Open ;
end else Begin
HL = HighD(1)-LowD(1) ;
Pivot = (HighD(1)+LowD(1)+CloseD(1))/3 ;
RT1 = CloseD(1) + HL*BaseRatio/12*Factor ;
RT2 = CloseD(1) + HL*BaseRatio/6*Factor ;
RT3 = CloseD(1) + HL*BaseRatio/4*Factor ;
RT4 = CloseD(1) + HL*BaseRatio/2*Factor ;
if LowD(1) <> 0 then RT5 = (HighD(1)/LowD(1))*CloseD(1)*BaseRatio ;
SP1 = CloseD(1) - HL*BaseRatio/12*Factor ;
SP2 = CloseD(1) - HL*BaseRatio/6*Factor;
SP3 = CloseD(1) - HL*BaseRatio/4*Factor;
SP4 = CloseD(1) - HL*BaseRatio/2*Factor ;
SP5 = (CloseD(1)*2 - RT5)*BaseRatio ;
Condition1 = Close > OpenD(0) and OpenD(0) > CloseD(1) ;
Condition2 = Close < OpenD(0) and OpenD(0) < CloseD(1) ;
OpenPrice = OpenD(0) ;
end;

Condition3 = Xaverage(AvgPrice,FastLen) > Xaverage(AvgPrice ,SlowLen) ;
Condition4 = Xaverage(AvgPrice,FastLen) < Xaverage(AvgPrice ,SlowLen) ;

{ Entries and Exits }
{if HL > HLrange and HL < 240 then Begin }

{ fade RT3 short entry 假突破}
if Type = 1 then Begin
if OpenPrice < RT3 and Close > RT3 then Sell ( "RT3_A" ) next bar RT3 Stop ;
ExitShort ( "RT3_FA" ) from entry ( "RT3_A" ) next bar RT4 stop ;
end;

{ fade SP3 long entry 假跌破}
if Type = 2 then Begin
if OpenPrice > SP3 and Close < SP3 then Buy ( "SP3_A" ) next bar SP3 Stop ;
ExitLong ( "SP3_FA" ) from entry ( "SP3_A" ) next bar SP4 stop ;
end;

{ trend trade cross SP3 long entry 作多試單}
if Type = 3 then Begin
if Close < SP3 then Buy ( "SP3_B" ) next bar SP3 stop ;
ExitLong ( "SP3_TA" ) from entry ( "SP3_B" ) next bar SP4 stop ;
end;

{ trend trade cross RT3 short entry 作空試單}
if Type = 4 then Begin
if Close > RT3 then Sell ( "RT3_B" ) next bar RT3 stop ;
ExitShort ( "RT3_TA" ) from entry ( "RT3_B" ) next bar RT4 stop ;
end;

{ RT4 breakout Entries 突破進場作多}
if Type = 5 then Begin
if Close < RT4 then Buy ( "RT4_A" ) next bar RT4 stop ;
ExitLong ( "RT4_AX" ) from entry ( "RT4_A" ) next bar RT3 stop ;
ExitLong ( "RT4_BX" ) from entry ( "RT4_A" ) next bar RT5 limit ;
end;

{ ST4 breakout Entries 跌破進場作空}
if Type = 6 then Begin
if Close > SP4 then Sell( "SP4_A" ) next bar SP4 stop ;
ExitShort ( "SP4_AX" ) from entry ( "SP4_A" ) next bar SP3 stop ;
ExitShort ( "SP4_BX" ) from entry ( "SP4_A" ) next bar SP5 limit ;
end;
{end;}

{ N根 Bar 平倉}
if MP > 0 and BarsSinceEntry = NbarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NbarS then ExitShort next bar at Market ;

{setProfitTarget(PF * BigPointValue) ;}
SetStopLoss(PL * BigPointValue) ;

if IsBalanceDay then SetExitonClose ;
基本設定:台指期 60 minK 留倉 ,回測期間 2001/1~2013/10/31 交易成本 1200
從 Type 1 ~ Type6 分別作測試組合 , 結果如下圖

看起來還有改善空間

0 留言:

張貼留言

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

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