Forex Basket Trading Strategy (Amibroker Code)

The original article can be found here.

Strategy in plain English:

  • When the EUR/USD pair breaks above the upper Bollinger Band (using 150 days and 2 standard deviations), we go long at the close.
  • We cover when the close breaks below the 150-day simple moving average.
  • We take the opposite position in AUD/USD (we short AUD/USD when we go long EUR/USD).

Amibroker code:

Fremmed=Foreign(“EURUSD=X”,”close”,fixup=1);

oddis=Optimize(“N-day”,150,10,200,10) ;


Fremmed=Foreign("EURUSD=X","close",fixup=1);
oddis=Optimize("N-day",150,10,200,10) ;

if( Name() == "EURUSD=X" )
{

IIf( Name() == "EURUSD=X",setPositionSize(49.75*leverage,spsPercentOfEquity),0);


Buy=Cross(C,BBandTop(C,oddis,2)) ;
buyPrice= C;
Sell=  Cross(MA(C,oddis),C);  
sellPrice= C;

}

if( Name() == "AUDUSD=x" )
{

IIf( Name() == "AUDUSD=x",setPositionSize(49.75*leverage,spsPercentOfEquity),0);


Short=Cross(fremmed,BBandTop(fremmed,oddis,2)) ;
shortprice= Close;
Cover=  Cross(MA(fremmed,oddis),fremmed);  
coverPrice= Close;


}