EasyTrader ArtNo 285
背離,技術分析中最強烈的訊號:對於任何特定的市場,MACD柱狀圖與價格之間的背離現象,每年頂多僅會發生幾次,它們是技術分析中明確的訊號。這種背離現象意味著主要的轉折點,代表「超級」的買進或賣出訊號。它們不會發生在每個重要的頭部或底部,但只要察覺這類的訊號。你知道主要的趨勢很可能發生反轉。
當價格漲勢創新高,而MACD柱狀圖的頭部卻下滑,形成空頭的背離(bearish divergence)。MACD柱狀圖的頭部下滑,顯示多頭在價格上漲的過程中已經露出疲態。多頭逐漸放盡力氣,空頭準備接手控制大局。MACD柱狀圖與價格之間的空頭背離現象,指出行情頭部的結構脆弱。
只要價格與MACD柱狀圖都持續創新低,就可以確認下降趨勢。如果價格創新低,而MACD柱狀圖的底部墊高,這形成多頭的背離(bullish divergence)。價格僅是仰賴慣性下跌.空頭是外強中乾,多頭即將主導盤勢。MACD柱狀圖與價格之間的多頭背離現象,指出行情底部潛藏著無限的生機。
{系統參數與變數}
input:EntryType(3),ExitType(2);
input:NBarL(10),NBarS(20),TradeProfit(0.02),TradeStopLoss(0.02),ATRs_L(1.5),ATRs_S(11.8);
vars:IsBalanceDay(False),MP(0),PF(0),PL(0);
input:LongLen(60),ShortLen(60),Fast(12),Ratio(2.2),AvgL(9),StrengthL(1),StrengthS(1),HighBar(3),LowBar(3) ;
vars:PriceUpA(0),PriceUpB(0),PriceDnA(0),PriceDnB(0),PBarUpA(0),PBarUpB(0),PBarDnA(0),PBarDnB(0) ;
vars:MBuySetUp(false),MSellSetup(false),Slow(0),OSC(0),Dem(0),Dif(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 ;
{利用參數來調整慢速線的差距}
Slow = IntPortion(Fast*Ratio)+1 ;
{計算自定的MACD柱狀圖}
Dif = Macd(Close,Fast,Slow) ;
Dem = Xaverage(Macd(Close,Fast,Slow),AvgL) ;
OSC = Dif-Dem ;
{買方條件設定}
{檢查是否最近是否發生低點轉折}
if SwingLowBar(1,Low,StrengthL,StrengthL*2+1) <> -1 then Begin
{若有低點轉折,再往前確認最近 N根K棒中是否有另一次同樣強度的低點轉折}
if SwingLowBar(2,Low,StrengthL,LongLen) <> -1 then Begin
if SwingLowBar(2,Low,StrengthL,LongLen) <> -1 then Begin
{若發生兩次轉折,則記錄轉折K棒編號,並回推兩次的最低點價位}
PBarUpB = SwingLowBar(2,Low,StrengthL,LongLen) ; {記錄K棒編號}
PBarUpA = SwingLowBar(1,Low,StrengthL,LongLen) ; {記錄K棒編號}
PriceUpB = Low[PBarUpB] ; {回推最低點價位}
PriceUpA = Low[PBarUpA] ;{回推最低點價位}
PBarUpB = SwingLowBar(2,Low,StrengthL,LongLen) ; {記錄K棒編號}
PBarUpA = SwingLowBar(1,Low,StrengthL,LongLen) ; {記錄K棒編號}
PriceUpB = Low[PBarUpB] ; {回推最低點價位}
PriceUpA = Low[PBarUpA] ;{回推最低點價位}
{若價格創新低但是柱狀圖高度未創低 - 正背離 - 買方條件成立}
if PriceUpA < PriceUpB and OSC[PBarUpA] > OSC[PBarUpB] then
MBuySetUp = true else MBuySetUp = false ;
if PriceUpA < PriceUpB and OSC[PBarUpA] > OSC[PBarUpB] then
MBuySetUp = true else MBuySetUp = false ;
{若沒發生轉低點轉折,取消買方條件}
end else MBuySetUp = false ;
end ;
end else MBuySetUp = false ;
end ;
{賣方條件設定}
{檢查是否最近是否發生高點轉折}
if SwingHighBar(1,High,StrengthS,StrengthS*2+1) <> -1 then Begin
{若有高點轉折,再往前確認最近 N根K棒中是否有另一次同樣強度的高點轉折}
if SwingHighBar(2,High,StrengthS,ShortLen) <> -1 then Begin
if SwingHighBar(2,High,StrengthS,ShortLen) <> -1 then Begin
{若發生兩次轉折,則記錄轉折K棒編號,並回推兩次的最高點價位}
PBarDnB = SwingHighBar(2,High,StrengthS,ShortLen) ;
PBarDnA = SwingHighBar(1,High,StrengthS,ShortLen) ;
PriceDnB = High[PBarDnB] ;
PriceDnA = High[PBarDnA] ;
PBarDnB = SwingHighBar(2,High,StrengthS,ShortLen) ;
PBarDnA = SwingHighBar(1,High,StrengthS,ShortLen) ;
PriceDnB = High[PBarDnB] ;
PriceDnA = High[PBarDnA] ;
{若價格創新高但是柱狀圖高度未創高 - 負背離 - 賣方條件成立}
if PriceDnA > PriceDnB and OSC[PBarDnA] < OSC[PBarDnB] then
MSellSetUp = true else MSellSetUp = false ;
if PriceDnA > PriceDnB and OSC[PBarDnA] < OSC[PBarDnB] then
MSellSetUp = true else MSellSetUp = false ;
{若沒發生轉高點轉折,取消賣方條件}
end else MSellSetUp = false ;
end;
{若買方條件成立,在近期高點買進作多 }
if MP <> 1 and MBuySetUp then Buy next bar at Highest(High,HighBar) stop ;
{若賣方條件成立,在近期低點賣出作空 }
if MP <> -1 and MSellSetUp then Sell next bar at Lowest(Low,LowBar) stop ;
end else MSellSetUp = false ;
end;
{若買方條件成立,在近期高點買進作多 }
if MP <> 1 and MBuySetUp then Buy next bar at Highest(High,HighBar) stop ;
{若賣方條件成立,在近期低點賣出作空 }
if MP <> -1 and MSellSetUp then Sell next bar at Lowest(Low,LowBar) stop ;
{出場選擇}
if ExitType = 0 then SetProfitTarget(PF * BigPointValue) ;
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 ;
if ExitType = 0 then SetProfitTarget(PF * BigPointValue) ;
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 ;
沒有留言:
張貼留言