EasyTrader ArtNo 120
布林線是由上限和下限兩條線構成的路徑型指標。當股價向上突破上限時視為超買,有回檔調整的可能,發出賣出信號;當股價向下突破下限時視為超賣,有反彈的要求,發出買入信號。但運用過程中我們發現,在爆發性行情中會突破上限後繼續揚升,在急挫行情中會突破下限後持續下跌,有時股價會緊貼上限(或下限)忽起忽落,單憑布林線要準確把握買賣時機有很大的難度。單獨使用布林線時,其應用上的盲點,布林帶寬度(Band width)的發展,適時解決了這方面的困擾。布林帶寬度(Band width)是由布林線所衍生出來的指標,被用來測量帶狀布林線的上限和下限,距離中間平均線的寬度。布林帶寬度主要的作用在於輔助布林線辨別買賣點的真偽。
統計上的基礎 :
股價落在正負1個標準差內的機率約有 68%
落在兩個標準差內的機率約有95%
選定了標準差的參數之後,我們就可以在K線圖上看到三條線,一是中線也就是平均線,一是均線上面的標準差線,一是均線下面的標準差線.
股價夾在兩條標準差線之間的區間就是所謂的「布林通道」
依據此原理 ,我們也可以將上下各2個標準差範圍的通道寬度的變化作為策略元素的參考
布林帶寬度 = StdDev(Close,20) * 4 ( 4 = 上下各 2個標準差 )
通道寬度的五根K棒內變化 = StdDev(布林帶寬度,5)
測試程式碼 [ 台指期 30 分K , 2004/1 ~2014/2 ,交易成本 1200 ]
Inputs: NL1(58),XL1(120),XS1(312),NBar_LE(41),Frac_LE(3),NBar_LM(41),Frac_LMM(3.26),NBar_SX(92);
Var: LE_ATR(0),LMM_ATR(0);
Var:UBuy(0),USell(0),BuyStop(0);
Var:VarL1(0),VarL2(0),VarS1(0),Cond_LE(false),Cond_SE(false),Cond_LX(false);
{ Average true range }
LE_ATR = Average(TrueRange, NBar_LE);
LMM_ATR = Average(TrueRange, NBar_LM);
{ Entry prices }
UBuy = CloseD(1) + Frac_LE * LE_ATR;
USell = LowD(0);
{ Entry and exit conditions }
VarL1 = XAverage(Open, NL1);
VarL2 = StdDev(StdDev(Close,20)*4,5);
VarS1 = StdDev(Close,20)*4;
Cond_LE = Low >= VarL1;
Cond_SE = VarS1 > XS1;
Cond_LX = VarL2 >= XL1;
If Cond_LE then begin
Buy next bar at UBuy stop;
end;
If Cond_SE then begin
Sell next bar at USell stop;
end;
If MarketPosition > 0 then begin
If BarsSinceEntry = 0 then begin
BuyStop = EntryPrice - Frac_LMM * LMM_ATR;
end;
If Cond_LX then
ExitLong next bar at market;
ExitLong next bar at BuyStop stop;
end;
If MarketPosition < 0 then begin
If BarsSinceEntry >= NBar_SX then
ExitShort next bar at market;
end;
測試程式碼 [ 台指期 60 分K , 2004/1 ~2014/2 ,交易成本 1200 ]
Inputs: XS1(19.1),Bar_L1(43),NBar_LE(15),Frac_LE(2.2),NBar_LM(20),Frac_LMM(4.3),
NBar_LX(82),NBar_SE(64),Frac_SE(2.38),NBar_SX(30);
Var:LE_ATR(0),LMM_ATR(0),SE_ATR(0);
Var:UBuy(0),USell(0),BuyStop(0);
Var:VarS1(0),Cond_LE(false),Cond_SE(false);
LE_ATR = Average(TrueRange, NBar_LE);
LMM_ATR = Average(TrueRange, NBar_LM);
SE_ATR = Average(TrueRange, NBar_SE);
{ Entry prices }
UBuy = XAverage(L, Bar_L1) + Frac_LE * LE_ATR;
USell = CloseD(1) - Frac_SE * SE_ATR;
{ Entry and exit conditions }
VarS1 = StdDev(StdDev(Close,20)*4,5);
Cond_LE = true;
Cond_SE = VarS1 >= XS1;
If Cond_LE then begin
Buy next bar at UBuy stop;
end;
If Cond_SE then begin
Sell next bar at USell stop;
end;
If MarketPosition > 0 then begin
If BarsSinceEntry = 0 then begin
BuyStop = EntryPrice - Frac_LMM * LMM_ATR;
end;
If BarsSinceEntry >= NBar_LX then
ExitLong next bar at market;
ExitLong next bar at BuyStop stop;
end;
If MarketPosition < 0 then begin
If BarsSinceEntry >= NBar_SX then
ExitShort next bar at market;
end;
VarL1 = XAverage(Open, NL1);
VarL2 = StdDev(StdDev(Close,20)*4,5);
VarS1 = StdDev(Close,20)*4;
Cond_LE = Low >= VarL1;
Cond_SE = VarS1 > XS1;
Cond_LX = VarL2 >= XL1;
If Cond_LE then begin
Buy next bar at UBuy stop;
end;
If Cond_SE then begin
Sell next bar at USell stop;
end;
If MarketPosition > 0 then begin
If BarsSinceEntry = 0 then begin
BuyStop = EntryPrice - Frac_LMM * LMM_ATR;
end;
If Cond_LX then
ExitLong next bar at market;
ExitLong next bar at BuyStop stop;
end;
If MarketPosition < 0 then begin
If BarsSinceEntry >= NBar_SX then
ExitShort next bar at market;
end;
測試程式碼 [ 台指期 60 分K , 2004/1 ~2014/2 ,交易成本 1200 ]
Inputs: XS1(19.1),Bar_L1(43),NBar_LE(15),Frac_LE(2.2),NBar_LM(20),Frac_LMM(4.3),
NBar_LX(82),NBar_SE(64),Frac_SE(2.38),NBar_SX(30);
Var:LE_ATR(0),LMM_ATR(0),SE_ATR(0);
Var:UBuy(0),USell(0),BuyStop(0);
Var:VarS1(0),Cond_LE(false),Cond_SE(false);
LE_ATR = Average(TrueRange, NBar_LE);
LMM_ATR = Average(TrueRange, NBar_LM);
SE_ATR = Average(TrueRange, NBar_SE);
{ Entry prices }
UBuy = XAverage(L, Bar_L1) + Frac_LE * LE_ATR;
USell = CloseD(1) - Frac_SE * SE_ATR;
{ Entry and exit conditions }
VarS1 = StdDev(StdDev(Close,20)*4,5);
Cond_LE = true;
Cond_SE = VarS1 >= XS1;
If Cond_LE then begin
Buy next bar at UBuy stop;
end;
If Cond_SE then begin
Sell next bar at USell stop;
end;
If MarketPosition > 0 then begin
If BarsSinceEntry = 0 then begin
BuyStop = EntryPrice - Frac_LMM * LMM_ATR;
end;
If BarsSinceEntry >= NBar_LX then
ExitLong next bar at market;
ExitLong next bar at BuyStop stop;
end;
If MarketPosition < 0 then begin
If BarsSinceEntry >= NBar_SX then
ExitShort next bar at market;
end;
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!