Afl to change percent hold between stock a and stock b

Hi,

I have written quite a few afls but can’t seem to get my head around how to do the follows. Ideas and example code that you might have is appreciated. I’m hoping that I do not need custom backtester but whatever works.

• I have a position score and can write regular or rotational AFL;
• AFL starts with $10000, placing all of the available monies into Stock A and Stock B based on the position score;
• with trades allowed only twice a month, say at the open on the 1st or 15th.

Let’s say the system is holding 82% of monies in Stock A and the rest or 18% in Stock B, and on the last day of the month the position score tells us to go to 60% in Stock A and 40% in Stock B the next day at the open. The next day we need to sell some of Stock A and buy some of Stock B.

I can’t get my head around how to do this in AFL. One approach is for the AFL to somehow tell me to go from 82%/18% to 60%/40% at the open on the first market day of the month. Then, I would take it from there with a calculator or Excel to determine how many shares to sell and buy. Another approach is for the afl to tell me how many shares of Stock A to sell and how many of Stock B to buy to get me to 60/40. This would be best for me but can handle either.

Help appreciated.

@bistrader It sounds like you need to use a rebalance code from the CBT. Another possible solution is to simulate re-balancing, you may be able to code more easily is to sell all positions (go 100% cash) and then Buy all new positions with your new allocations. Just don’t include slippage or commissions since this would only simulate your re-balancing.

Rebalance CBT,
http://www.amibroker.com/kb/2006/03/06/re-balancing-open-positions/

Also look through this forum for “reblance” posts, maybe something like this can help