Buy every month with some accelleration

Hi i would like to ask what is the most efficent way of writing the following rules in amibroker, can i have some example code?

Starting capital is 1.000.000 usd

  1. The first day i invest 10% of capital
  2. Each month (last day of month)i buy 8.000 usd worth of one stock
  3. When maximum drawdown up to that day is below 15%, i buy 10 times 8.000 usd (80.000 usd)
  4. When maximum drawdown up to that day is below 25%, i buy 10 times 8.000 usd (80.000 usd)
  5. When my 1.000.000 usd runs out, the strategy becomes buy & hold.

Thank you

Starting point for pyramiding is described in the manual:
http://www.amibroker.com/guide/h_pyramid.html