It's like rotational trading - but not quite!

Hi,

I am not sure how to do this in AFL - it's similar to rotational trading, but using buy/sell arrays (which are not used in rotational mode - hence my asking here how to do this).

I am using Buy/Sell arrays to define entry and exit points. These are at certain dates eg- Jan 05 2003 as an entry, and 1st April 2008 as an exit.

When Buy date==1, I would like to buy the 5 lowest priced stocks in my watchlist - and hold all these stocks until Sell date==1. On the sell date, all stocks are sold and exited.

I then wait for the next Buy signal - and repeat the process.

How would I do this?

Thanks,
Alex

Based on the limited information you have provided, you can start with the following:

  1. Set the maximum open positions to 5, via the Settings window or using SetOption().
  2. Assign the Buy and Sell arrays according to your entry and exit dates.
  3. Assign your ranking value to the built-in PositionScore value, being careful to note that AmiBroker prioritizes trades by the absolute value of PositionScore, so for example -3 is ranked higher than +2.

Thanks for your reply, but that doesn't really help me.

I thought buy/sell arrays were not used in rotational trading.

Anyone?

But you haven't clarified whether you are using the Rotational Trading mode of AB.
You have just written like and similar to Rotational Trading.

Have you specified EnableRotationalTrading(); in the code? Also, this is obsolete and should use the newer SetBacktestMode( backtestRotational );

Since you yourself mention the use of Buy/Sell arrays in Line of 1st post, Matt seems to be referencing that.

You could share a code example too.

1 Like

OK, thanks - some confusion in my post then.

I haven't got any AFL yet - I was wondering how to go about it. I don't mind if I use rotational trading or not - I came across this method when I was doing my initial research and was not sure if it was right for my idea.

I know how to populate the buy/sell arrays.

I don't know how to code a backtest to buy the lowest priced 5 stocks when Buy==1, hold them until sell==1, then on the next Buy==1 buy the next set of 5 priced lowest stocks.

Does that clarify it?

I don't know how to code a backtest to buy the lowest priced 5 stocks when Buy==1, hold them until sell==1, then on the next Buy==1 buy the next set of 5 priced lowest stocks.

I don't think this would classify as Rotational Trading. It appears to be merely a Long only Trading system with Ranking.
Maybe you can see this https://www.amibroker.com/guide/h_ranking.html
and see if StaticVarGenerateRanks() can be more useful.

When you get a buy signal, again you haven't defined its criteria, but lets say the index has fallen X%,
then you can Rank all you scrips, Buy the bottom 5 Rank and just hold.
When Sell appears, exit all positions.
Repeats again for a new Buy.

There a good example in the link based on RoC() ranking as well.

Thanks travick, I'll take a look and come back if I have further questions

@travick is correct that I gave you a solution based on the question you posted.

As I said in my first post, you simply need to assign the PositionScore variable. No need to use StaticVarGenerateRanks() unless you have additional criteria that you haven't told us about. Have you taken the time to research that?

2 Likes

Positionscore did help - thanks for mentioning it. I had got confused on which backtest mode to use.