Long Short Equity Strategy (Amibroker Code)

The original article can be found here.

Plain English:

  1. We create a pair ratio that is simply the price of KO divided by PEP.
  2. We create a 5-day RSI of the pair.
  3. If the RSI value in no. 2 goes below 20, we invest 50% of the equity in KO and short 50% in PEP.
  4. When the RSI value returns to 60, we cover both our positions done in no 3.
  5. If the RSI value in no. 2 goes above 80, we spend 50% of the equity short-selling KO and spend the remaining 50% on a long position in PEP.
  6. We cover our position from no 5 if the RSI value goes below 40.

Amibroker code:

Fremmed=Foreign("KO","close",fixup=1);
Fremmedto=Foreign("PEP","close",fixup=1);

Pair= fremmed/fremmedto ;
RSIpair=RSIa(pair,5);

setPositionSize(49.75*leverage,spsPercentOfEquity) ;

if( Name() == "KO" )
{


Buy = Cross(20,rsipair)   ;
BuyPrice=Close;
Sell = Cross(rsipair,60)  ;
SellPrice = Close;

Short= Cross(rsipair,80);
ShortPrice= Close ;
Cover= Cross(40,rsipair) ;
CoverPrice= close;


}

if( Name() == "PEP" )
{

Buy = Cross(rsipair,80)  ;
BuyPrice=Close;
Sell = Cross(40,rsipair)  ;
SellPrice = Close;




Short = Cross(20,rsipair)  ;
shortPrice=Close;
Cover = Cross(rsipair,60) ;
coverPrice = Close;




}