2022-01-01|閱讀時間 ‧ 約 4 分鐘

程式碼分析.11

在ADX、DMI,這指標同時處理波動度與方向力道大小程度,不愧是指標中的第一名首選濾網 ! 以下先介紹計算流程與公式
步驟1,前後兩根K棒的多空力道大小,分為上述六種狀態
步驟1,前後兩根K棒的多空力道大小,分為上述六種狀態
步驟2,評估多空力道移動總距離的方法
步驟3,分子採用離差概念,分母取總距離,在取其平均值
{DMI-ADX} Input:DMILen(7),ADXLen(7),ADXExit(30),Trade(10000),Lot(100); Vars:BuySetup(false),SellSetup(false),BuyPrice(0),SellPrice(0),DPlus(0),DMin(0),ADXVal(0),ExitSPrc(0),ExitLPrc(0);
DPlus = DMIPlus(DMILen); DMin = DMIMinus(DMILen); ADXVal = ADX(ADXLen);
If DPlusDMin AND ADXVal Crosses Over DMin and MarketPosition 1 then begin BuyPrice = High; BuySetup = true; ExitLPrc = Low; End; If ADXValDMin or MarketPosition = 1 then BuySetup = False;
If DPlus DMin AND ADXVal Crosses Over DPlus and MarketPosition -1 then begin SellPrice = Low; SellSetup = true; ExitSPrc = High; End; If ADXVal DPlus or MarketPosition = -1 then SellSetup = False;
If BuySetup then Buy 1 Contracts next bar at BuyPrice stop; If SellSetup then SellShort 1 Contracts next bar at SellPrice stop;
If MarketPosition = 1 then Begin BuySetup = false; sell next bar at ExitLPrc Stop; End;
If MarketPosition = -1 then begin SellSetup = True; Buytocover next bar at ExitSPrc stop; End;
{ADX Exit Strategy} If (ADXVal[1]=ADXExit and ADXValADXVal[1]) then Begin If MarketPosition=1 and BarssinceEntry1 then sell this bar at close; If MarketPosition=-1 and BarsSinceEntry1 then buytocover this bar at close; End;
If DPlusDMin and BarsSinceEntry1 then sell next bar at Lowest(Low,3) stop; If DPlusDmin and BarsSinceEntry1 then buytocover next bar at Highest(High,3) stop;
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.