EasyTrader ArtNo 253
Commodity Channel Index (CCI) 順勢指標是由美國股市分析家 Donald Lambert 所創,由 CCI 的英文名稱己清楚說明,它最早是用於期貨市場,後在股票市場也被廣泛使用。CCI 假設期貨價格是有一定的週期性,把價格與股價平均區間的偏離程度以正負值在圖表上展示。CCI不是以零軸來分界多空;CCI 率先引進了過濾線的使用,數據的+100/-100為兩條過濾線, 在這兩條過濾線之內歸類為盤整盤, 而行情超過了上下線, 則是偏激的多頭與空頭趨勢行情
CCI指標的運行區間也分為三類:+100以上為超買區,-100以下為超賣區,+100到-100之間為震蕩區。
當CCI > +100時,表明股價已經進入超買區間,股價的異動現象應多加關注。
當CCI < -100時,表明股價已經進入超賣區間,投資者可以逢低吸納股票。
當CCI 介於 +100 和 -100之間時表明股價處於窄幅振蕩整理的區間,投資者應以觀望為主。
測試程式碼
input:EntryType(1),ExitType(1);
inputs:NBarL(30),NBarS(27),TradeProfit(0.03),TradeStopLoss(0.04),ATRs_L(15),ATRs_S(10);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0),HLRange(100);
inputs: CCILen(20), AvgLen(10),CCILenS(20), AvgLenS(10), HB(-100), LB(100), HighBar(4), LowBar(11);
Vars: AvgCCI(0),AvgCCISlow(0), BSetup(False), SSetup(False);
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 ;
{Calculation of Average CCI and determination of setup conditions}
AvgCCI = Average(CCI(CCILen), AvgLen);
AvgCCISlow = Average(CCI(CCILen), AvgLen*3);
BSetup = AvgCCI Crosses over HB;
SSetup = AvgCCI Crosses under LB;
{ 突破分界線 }
if EntryType = 1 then Begin
{Long Entry}
IF MP <> 1 and AvgCCI > HB AND MRO(BSetup, 5, 1) <> -1 Then
Buy Next Bar at Highest(High, HighBar)[1] Stop;
{Short Entry}
IF MP <> -1 and AvgCCI < LB AND MRO(SSetup,5, 1) <> -1 Then
Sell Next Bar at Lowest(Low, LowBar)[1] Stop;
end;
{長短均線交叉}
if EntryType = 2 then Begin
if MP <> 1 and AvgCCI Cross over AvgCCISlow then Buy next bar at Highest(High,Highbar) stop ;
if MP <> -1 and AvgCCI Cross under AvgCCISlow then Sell next bar at Lowest(Low,Lowbar) stop ;
end ;
{Exits}
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) ;
setProfitTarget(PF * BigPointValue) ;
if MP > 0 and BarsSinceEntry = NBarL then {Sell } ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then {Buy} ExitShort next bar at Market ;
end;
if IsBalanceDay or date = 1150224 then setExitonClose ;
策略一台指期 60 min K 留倉 交易期間 2004/12/31 ~ 2014/12/31 交易成本 1200
策略二台指期 60 min K 留倉 交易期間 2004/12/31 ~ 2014/12/31 交易成本 1200
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) ;
setProfitTarget(PF * BigPointValue) ;
if MP > 0 and BarsSinceEntry = NBarL then {Sell } ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then {Buy} ExitShort next bar at Market ;
end;
if IsBalanceDay or date = 1150224 then setExitonClose ;
策略一台指期 60 min K 留倉 交易期間 2004/12/31 ~ 2014/12/31 交易成本 1200
策略二台指期 60 min K 留倉 交易期間 2004/12/31 ~ 2014/12/31 交易成本 1200
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!