3 Free Mean Reversion Strategies (Amibroker And Tradestation Code)
The strategies on this page were summarized in this article.
Strategy 1: Deviation from a recent high in XLP
The strategy in plain English:
- Calculate an average of the H-L over the last 25 days.
- Calculate the (C-L)/(H-L) ratio every day (IBS).
- Calculate a band 2.25 times lower than the high over the last 25 days by using the average from point number 1 (βATRβ).
- If XLP closes under the band in number 3, and point 2 (IBS) has a lower value than 0.6, then go long at the close.
- Exit when the close is higher than yesterday’s high.
Amibroker code:
range=MA((H-L),25);
OddisHigh=HHV(H,25);
OddisLow=LLV(L,25);
OddisBandLong=OddisHigh – (range*2.25);
OddisBandShort=OddisLow + (range*2.25);
Buy= Close<OddisBandLong AND ibs<0.6;
buyPrice= C;
Sell= C>Ref(H,-1);
sellPrice= Close ;
Tradestation code:
If IFF((H-L)<>0,((C-L))/(H-L),1)< 0.6
and c<=high-2.25*average(range,25)
then buy this bar at close;
If c>h[1] then sell this bar at close;
Strategy 2: Short IBS strategy in FXI
The strategy in plain English:
- If today’s IBS (C-L)/(H-L) is higher than 0.9 then short at the close.
- Exit at the close when the IBS is 0.25 or lower.
Amibroker code:
ibs=(C-L)/(H-L) ;
Short=ibs>0.9 ;
ShortPrice=Close ;
Cover=ibs<0.25 ;
CoverPrice= Close ;
Tradestation code:
If IFF((H-L)<>0,((C-L))/(H-L),1) > 0.9
then sell short this bar at close;
If IFF((H-L)<>0,((C-L))/(H-L),1) < 0.25
then buy to cover this bar at close;
Strategy 3: 5-day low in the S&P 500
The strategy in plain English:
- If today’s close is below yesterday’s five-day low, go long at the close.
- Sell at the close when the two-day RSI closes above 50.
- We have a time stop of five days if the sell criterium is not triggered.
Amibroker code:
Buy= Close<Ref(LLV(L,5),-1) ;
buyPrice= C;
Sell= RSI(2)>50 ;
sellPrice= Close ;
ApplyStop(stopTypeNBar,stopModeBars,5,1);
Tradestation code:
If c < lowest(low,5)[1]
then buy this bar at close;
If (RSI(c,2)>50 or barssinceentry=5) then sell this bar at close;
Disclaimer: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions β they are not suggestions to buy or sell any securities.
