簡易的動能策略(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 PriceOsc>PriceOscAgo AND PriceOsc<0 AND Close>AvgFilter Then Buy Next Bar at Market;
{Short Entry}
If PriceOsc < PriceOscAgo AND PriceOsc>0 AND Close<AvgFilter 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;