Dollar-Cost Averaging (Amibroker code)

The relevant article can be found here.

This is the Amibroker code for both lump-sum investment and dollar-cost averaging:

A lump-sum investment:

SetOption(“InitialEquity”, 60000);

Buy=C>0 ; // we go long at the close of the first day
Sell= 0;  // we never sell

Dollar-cost averaging:

SetOption(“InitialEquity”, 60000); // we DCA 60 000 by investing 250 each month – in total 60 000
SetPositionSize(250,spsValue); //we invest 250 each month

MonthBegin = Month() != Ref( Month(), -1 ); // we invest on first day of the month

Buy= IIf(MonthBegin, sigScaleIn,0);  //if new month we scale in
Sell= 0;  //we never sell