2021-12-28|閱讀時間 ‧ 約 3 分鐘

程式碼分析.8

簡易的動能策略(rate of change)概念
{Swinger} Inputs:FastLen(5),SlowLen(20),AvgLen(50),Nbars(3),ProtATR(3),ATRLen(10); Variables:PriceOsc(0),PriceOscAgo(0),AvgFilter(0),ATRValP(0); ATRValP=AvgTrueRange(ATRLen)*ProtATR; {Variables are defined} PriceOsc=PriceOscillator(Close,FastLen,SlowLen); {PriceOscillator=Average(Price,Slow)-Average(Price,Fast);} PriceOscAgo=PriceOsc[1]; AvgFilter=Average(Close,AvgLen);
{Long Entry} If PriceOscPriceOscAgo AND PriceOsc0 AND CloseAvgFilter Then Buy Next Bar at Market; {Short Entry} If PriceOsc PriceOscAgo AND PriceOsc0 AND CloseAvgFilter Then SellShort Next Bar at Market;
{Long Exit} If MarketPosition = 1 Then Begin If PriceOsc PriceOscAgo Then sell Next Bar at Lowest(Low, NBars) Stop; End;
{Short Exit} If MarketPosition = -1 Then Begin If PriceOsc PriceOscAgo Then BuyToCover Next Bar at Highest(High, NBars) Stop; 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;
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.