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

程式碼分析.17

拋物線SAR(Stop and Reverse),好用的出場概念,但是常常被搞錯認為是進場的邏輯,廢話不多說,請參考程式碼的出場部分
Input:ATRLength(10),ATRs(2.5); Vars:WAvgPrice(0),Resistance(0),Support(0); Vars:EntryATR(0),MP(0),StopPrice(0);
WAvgPrice=(High+Low+2*Close)*0.25; Resistance=2*WAvgPrice-Low; Support=2*WAvgPrice-High; MP=MarketPosition;
If MP1 then Buy next bar at Resistance Stop; If MP-1 then SellShort next bar at Support Stop;
{ Exit with ATR Profit Target } If BarsSinceEntry=0 then EntryATR=AvgTrueRange(ATRLength)*ATRs; If MP=1 and HighEntryPrice+EntryATR then Sell next bar at EntryPrice+EntryATR Stop; If MP=-1 and LowEntryPrice-EntryATR then BuyToCover next bar at EntryPrice-EntryATR Stop;
{ Exit with Parabolic SAR } If MP=1 and MP[1]=0 then StopPrice=Low-Average(Range,4); If MP=-1 and MP[1]=0 then StopPrice=High+Average(Range,4);
If MP=1 then begin Sell next bar at StopPrice Stop; StopPrice = StopPrice+(Low-StopPrice)/3; End;
If MP=-1 then begin BuyToCover next bar at StopPrice Stop; StopPrice = StopPrice-(StopPrice-High)/3; End;
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.