ADX這個指標可以同時衡量波動度與行情方向,也因為內在的出頭落尾設計邏輯可以多方變化(利用創新高、創新低的動能,作為多空力道的判斷依據),長久以來就是模組開發練功的第一步
ADX指標常見的建構模組邏輯如下 : 1. 在波動度放大的時候進場(Ex. ADX(10)ADX(10)[1])
2. 也可用在 ADX縮小至某個門檻值之下,判定為盤整,搭配其他突破訊號進場
以下為參考程式碼
{Traffic Jam}
Inputs:ADXLen(14),ADXLev(25),ConsecDC(3),ConsecUC(3),ProtATR(3),ATRLen(10),FixdExit(3);
Variables:ADXVal(0),ATRValP(0);
ADXVal=ADX(ADXLen);
ATRValP=AvgTrueRange(ATRLen)*ProtATR;
{Setup Criteria for System Entries}
Condition1 = ADXVal ADXLev AND ADXVal ADXVal[MaxList(ConsecDC, ConsecUC)]; Condition2 = CountIf(Close Close[1], ConsecDC) = ConsecDC; Condition3 = CountIf(Close Close[1], ConsecUC) = ConsecUC;
{System Entries}
If Condition1 Then Begin
If Condition2 Then
Buy This Bar on Close;
If Condition3 Then
SellShort This Bar on Close;
End;
{ATR Protective Stop}
If MarketPosition = 1 Then
Sell Next Bar at EntryPrice - ATRValP Stop;
If MarketPosition = -1 Then
BuyToCover Next Bar at EntryPrice + ATRValP Stop;
{Fixed Bar Exit}
If BarsSinceEntry = FixdExit Then
Sell This Bar on Close;
If BarsSinceEntry = FixdExit Then
BuyToCover This Bar on Close;